[MLton-commit] r6637
Vesa Karvonen
vesak at mlton.org
Wed Jun 4 05:24:47 PDT 2008
Added "minimal" random number generator, Ran0Gen, of Park and Miller as
described in Numerical Recipes in C (section 7.1).
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/random/unstable/LICENSE
U mltonlib/trunk/com/ssh/random/unstable/detail/ml/smlnj/unsealed.cm
A mltonlib/trunk/com/ssh/random/unstable/detail/ran0-gen.sml
U mltonlib/trunk/com/ssh/random/unstable/lib.mlb
U mltonlib/trunk/com/ssh/random/unstable/lib.use
U mltonlib/trunk/com/ssh/random/unstable/public/export.sml
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/random/unstable/LICENSE
===================================================================
--- mltonlib/trunk/com/ssh/random/unstable/LICENSE 2008-06-02 14:11:27 UTC (rev 6636)
+++ mltonlib/trunk/com/ssh/random/unstable/LICENSE 2008-06-04 12:24:46 UTC (rev 6637)
@@ -1,6 +1,7 @@
COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+Copyright (C) 2008 Vesa Karvonen
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
Modified: mltonlib/trunk/com/ssh/random/unstable/detail/ml/smlnj/unsealed.cm
===================================================================
--- mltonlib/trunk/com/ssh/random/unstable/detail/ml/smlnj/unsealed.cm 2008-06-02 14:11:27 UTC (rev 6636)
+++ mltonlib/trunk/com/ssh/random/unstable/detail/ml/smlnj/unsealed.cm 2008-06-04 12:24:46 UTC (rev 6637)
@@ -1,4 +1,5 @@
(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ * Copyright (C) 2008 Vesa Karvonen
*
* This code is released under the MLton license, a BSD-style license.
* See the LICENSE file or http://mlton.org/License for details.
@@ -12,5 +13,6 @@
../../../public/rng.sig
../../mk-random-gen.fun
../../numerical-recipes.sml
+ ../../ran0-gen.sml
../../ranqd1-gen.sml
../common/random-dev.sml
Added: mltonlib/trunk/com/ssh/random/unstable/detail/ran0-gen.sml
===================================================================
--- mltonlib/trunk/com/ssh/random/unstable/detail/ran0-gen.sml 2008-06-02 14:11:27 UTC (rev 6636)
+++ mltonlib/trunk/com/ssh/random/unstable/detail/ran0-gen.sml 2008-06-04 12:24:46 UTC (rev 6637)
@@ -0,0 +1,29 @@
+(* Copyright (C) 2008 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+structure Ran0Gen :> RANDOM_GEN where type RNG.Seed.t = Word32.t =
+ MkRandomGen
+ ((* <-- SML/NJ workarounds *)
+ open TopLevel
+ infixr 4 />
+ (* SML/NJ workarounds --> *)
+ structure Seed = Word32
+ type t = Seed.t
+ val ia : t = 0w16807
+ val im : t = 0wx7FFFFFFF
+ val iq : t = 0w127773
+ val ir : t = 0w2836
+ fun make s = case Seed.andb (s, im) of 0w0 => 0w12345678 | s => s
+ fun value s = Seed.toWord (s - 0w1)
+ fun next s = let
+ val k = s div iq
+ val a = ia * (s - k * iq)
+ val b = ir * k
+ in
+ if a < b then a - b + im else a - b
+ end
+ fun split w = make o #2 o NumericalRecipes.psdes /> Seed.fromWord w
+ val maxValue = Seed.toWord (im - 0w2))
Property changes on: mltonlib/trunk/com/ssh/random/unstable/detail/ran0-gen.sml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: mltonlib/trunk/com/ssh/random/unstable/lib.mlb
===================================================================
--- mltonlib/trunk/com/ssh/random/unstable/lib.mlb 2008-06-02 14:11:27 UTC (rev 6636)
+++ mltonlib/trunk/com/ssh/random/unstable/lib.mlb 2008-06-04 12:24:46 UTC (rev 6637)
@@ -1,4 +1,5 @@
(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ * Copyright (C) 2008 Vesa Karvonen
*
* This code is released under the MLton license, a BSD-style license.
* See the LICENSE file or http://mlton.org/License for details.
@@ -21,6 +22,7 @@
public/numerical-recipes.sig
detail/numerical-recipes.sml
+ detail/ran0-gen.sml
detail/ranqd1-gen.sml
detail/ml/$(SML_COMPILER)/random-dev.mlb
Modified: mltonlib/trunk/com/ssh/random/unstable/lib.use
===================================================================
--- mltonlib/trunk/com/ssh/random/unstable/lib.use 2008-06-02 14:11:27 UTC (rev 6636)
+++ mltonlib/trunk/com/ssh/random/unstable/lib.use 2008-06-04 12:24:46 UTC (rev 6637)
@@ -10,6 +10,7 @@
"detail/mk-random-gen.fun",
"public/numerical-recipes.sig",
"detail/numerical-recipes.sml",
+ "detail/ran0-gen.sml",
"detail/ranqd1-gen.sml",
"public/random-dev.sig",
"detail/ml/${SML_COMPILER}/random-dev.use",
Modified: mltonlib/trunk/com/ssh/random/unstable/public/export.sml
===================================================================
--- mltonlib/trunk/com/ssh/random/unstable/public/export.sml 2008-06-02 14:11:27 UTC (rev 6636)
+++ mltonlib/trunk/com/ssh/random/unstable/public/export.sml 2008-06-04 12:24:46 UTC (rev 6637)
@@ -1,4 +1,5 @@
(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ * Copyright (C) 2008 Vesa Karvonen
*
* This code is released under the MLton license, a BSD-style license.
* See the LICENSE file or http://mlton.org/License for details.
@@ -17,6 +18,9 @@
structure RandomDev : RANDOM_DEV = RandomDev
(** The default/system random device. *)
+structure Ran0Gen : RANDOM_GEN where type RNG.Seed.t = Word32.t = Ran0Gen
+(** "Minimal" random number generator of Park and Miller. *)
+
structure RanQD1Gen : RANDOM_GEN where type RNG.Seed.t = Word32.t = RanQD1Gen
(** A quick-and-dirty random value generator. *)
More information about the MLton-commit
mailing list