From 5be3e42f30800e49b2bf9d92f627f2eb89efc8a9 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 5 Oct 2005 05:45:58 +0000 Subject: [PATCH] Uses array instead of sequence off by one on sequence initial size corrected [ 1 + ] change => inc --- contrib/crypto/mt.factor | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/contrib/crypto/mt.factor b/contrib/crypto/mt.factor index 46a76100e5..aa155f834c 100644 --- a/contrib/crypto/mt.factor +++ b/contrib/crypto/mt.factor @@ -7,7 +7,7 @@ ! initializes to seed 5489 automatically IN: crypto -USING: kernel math namespaces sequences ; +USING: kernel math namespaces sequences arrays ; : N 624 ; inline : M 397 ; inline @@ -41,25 +41,19 @@ SYMBOL: mti : generate-new-mt N M - [ dup y over dup M + set-mt-ith ] repeat - M 1 - [ dup 227 + dup y over dup M N - + set-mt-ith drop ] repeat + M 1- [ dup 227 + dup y over dup M N - + set-mt-ith drop ] repeat 0 mti set ; -: init ( seed -- ) - [ N 1- [ drop 0 , ] each ] { } make swap +: init-random ( seed -- ) + N zero-array swap HEX: ffffffff bitand 0 pick set-nth N 1- [ 2dup formula 1+ pick pick 1+ swap set-nth ] repeat mt set 0 mti set generate-new-mt ; : genrand ( -- rand ) - mti get - { ! leave mti - { [ dup not ] [ drop 5489 init 0 ] } - { [ dup N < ] [ ] } - { [ t ] [ drop generate-new-mt 0 ] } - } cond - mt get nth temper - mti [ 1+ ] change ; + mti get dup N < [ drop generate-new-mt 0 ] unless + mt get nth temper mti inc ; USE: compiler USE: test