]> gitweb.factorcode.org Git - factor.git/commitdiff
fix seed-random for cmwc
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 8 Oct 2009 01:21:09 +0000 (20:21 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 8 Oct 2009 01:21:09 +0000 (20:21 -0500)
extra/random/cmwc/cmwc-tests.factor
extra/random/cmwc/cmwc.factor

index 35785923f20a8301aacaf65da461fb16ce005625..2a908c0bd321572919c2467d3b405d0ef0066cc8 100644 (file)
@@ -30,13 +30,13 @@ IN: random.cmwc.tests
 ] unit-test
 
 [ t ] [
-    cmwc-4096
-    4096 iota >array seed-random [
-        10 [ random-32 ] replicate
-    ] with-random
-
-    cmwc-4096
-    4096 iota >array seed-random [
-        10 [ random-32 ] replicate
-    ] with-random =
+    cmwc-4096 [
+        4096 iota >array 362436 <cmwc-seed> seed-random [
+            10 [ random-32 ] replicate
+        ] with-random
+    ] [
+        4096 iota >array 362436 <cmwc-seed seed-random [
+            10 [ random-32 ] replicate
+        ] with-random
+    ] bi =
 ] unit-test
index 471c616247c5bc4e40b175c6686f0915b95cbe34..104046821fda903108c262bb8a8e12fbbcb63fa3 100644 (file)
@@ -19,9 +19,15 @@ TUPLE: cmwc-seed Q c ;
         dup b>> 1 - >>r
         dup Q>> length 1 - >>mod ;
 
+: <cmwc-seed> ( Q c -- cmwc-seed )
+    cmwc-seed new
+        swap >>c
+        swap >>Q ; inline
+
 M: cmwc seed-random
-    [ >>Q ]
-    [ length 1 - >>i ] bi ;
+    [ Q>> >>Q ]
+    [ Q>> length 1 - >>i ]
+    [ c>> >>c ] tri ;
 
 M:: cmwc random-32* ( cmwc -- n )
     cmwc dup mod>> '[ 1 + _ bitand ] change-i