From 926ed2d5e16553f3543824d2b75021689707a3e6 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 2 Oct 2009 00:21:48 -0500 Subject: [PATCH] cleaning up sfmt --- basis/random/sfmt/sfmt-tests.factor | 4 +++- basis/random/sfmt/sfmt.factor | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/basis/random/sfmt/sfmt-tests.factor b/basis/random/sfmt/sfmt-tests.factor index 53a134dbb8..674693805d 100644 --- a/basis/random/sfmt/sfmt-tests.factor +++ b/basis/random/sfmt/sfmt-tests.factor @@ -1,6 +1,8 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: tools.test random.sfmt ; +USING: accessors kernel random.sfmt sequences tools.test ; IN: random.sfmt.tests [ ] [ 100 drop ] unit-test +[ 1096298955 ] +[ 100 generate generate state>> first first ] unit-test diff --git a/basis/random/sfmt/sfmt.factor b/basis/random/sfmt/sfmt.factor index a8fab9f3ab..5fe4c43a13 100644 --- a/basis/random/sfmt/sfmt.factor +++ b/basis/random/sfmt/sfmt.factor @@ -17,7 +17,7 @@ CONSTANT: state-multiplier 1812433253 TUPLE: sfmt sl1 sl2 sr1 sr2 mask parity { seed integer } { n fixnum } { m fixnum } -{ ix fixnum } { state uint-4-array } ; +{ m-n fixnum } { ix fixnum } { state uint-4-array } ; : init-state ( sfmt -- sfmt' ) dup [ n>> 4 * iota >uint-array ] [ seed>> ] bi @@ -55,8 +55,9 @@ M:: sfmt generate ( sfmt -- sfmt' ) sfmt n>> 1 - sfmt state>> nth :> r2! 0 :> r! 0 :> i! - sfmt n>> :> n sfmt m>> :> m + sfmt n>> :> n + sfmt m-n>> :> m-n sfmt mask>> :> mask sfmt state>> :> state @@ -71,10 +72,10 @@ M:: sfmt generate ( sfmt -- sfmt' ) r r2! ] each - i 1 + n [a,b) [ + n m - 1 + n [a,b) [ i! i state nth - m n - i + state nth + m-n i + state nth mask r1 r2 formula r! r i state set-nth @@ -95,6 +96,7 @@ M:: sfmt generate ( sfmt -- sfmt' ) swap >>m swap >>n swap 32 bits >>seed + dup [ m>> ] [ n>> ] bi - >>m-n 0 >>ix init-state generate ;