Uses array instead of sequence

off by one on sequence initial size corrected
[ 1 + ] change  => inc
cvs
Doug Coleman 2005-10-05 05:45:58 +00:00
parent 7192167304
commit 5be3e42f30
1 changed files with 6 additions and 12 deletions

View File

@ -7,7 +7,7 @@
! initializes to seed 5489 automatically ! initializes to seed 5489 automatically
IN: crypto IN: crypto
USING: kernel math namespaces sequences ; USING: kernel math namespaces sequences arrays ;
: N 624 ; inline : N 624 ; inline
: M 397 ; inline : M 397 ; inline
@ -41,25 +41,19 @@ SYMBOL: mti
: generate-new-mt : generate-new-mt
N M - [ dup y over dup M + set-mt-ith ] repeat 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 ; 0 mti set ;
: init ( seed -- ) : init-random ( seed -- )
[ N 1- [ drop 0 , ] each ] { } make swap N zero-array swap
HEX: ffffffff bitand 0 pick set-nth HEX: ffffffff bitand 0 pick set-nth
N 1- [ 2dup formula 1+ pick pick 1+ swap set-nth ] repeat N 1- [ 2dup formula 1+ pick pick 1+ swap set-nth ] repeat
mt set 0 mti set mt set 0 mti set
generate-new-mt ; generate-new-mt ;
: genrand ( -- rand ) : genrand ( -- rand )
mti get mti get dup N < [ drop generate-new-mt 0 ] unless
{ ! leave mti mt get nth temper mti inc ;
{ [ dup not ] [ drop 5489 init 0 ] }
{ [ dup N < ] [ ] }
{ [ t ] [ drop generate-new-mt 0 ] }
} cond
mt get nth temper
mti [ 1+ ] change ;
USE: compiler USE: compiler
USE: test USE: test