random numbers were endian-dependent. clean up blum-blum-shub a bit

db4
Doug Coleman 2008-09-11 01:11:17 -05:00
parent 61a1625880
commit 800b134fa7
3 changed files with 2 additions and 4 deletions

View File

@ -14,7 +14,7 @@ GENERIC: random-32* ( tuple -- r )
GENERIC: random-bytes* ( n tuple -- byte-array )
M: object random-bytes* ( n tuple -- byte-array )
swap [ drop random-32* ] with map >c-uint-array ;
[ random-32* ] curry replicate [ 4 >le ] map concat ;
M: object random-32* ( tuple -- r ) 4 random-bytes* le> ;

View File

@ -11,14 +11,12 @@ IN: blum-blum-shub.tests
[ 70576473 ] [
T{ blum-blum-shub f 590695557939 811977232793 } clone [
32 random-bits
little-endian? [ <uint> reverse *uint ] unless
] with-random
] unit-test
[ 5570804936418322777 ] [
T{ blum-blum-shub f 590695557939 811977232793 } clone [
64 random-bits
little-endian? [ <ulonglong> 4 group [ reverse ] map concat *ulonglong ] unless
] with-random
] unit-test

View File

@ -13,7 +13,7 @@ TUPLE: blum-blum-shub x n ;
[ [ random-prime ] curry [ 4 mod 3 = ] generate ] dup bi ;
: next-bbs-bit ( bbs -- bit )
[ [ x>> 2 ] [ n>> ] bi ^mod dup ] keep (>>x) 1 bitand ;
dup [ x>> 2 ] [ n>> ] bi ^mod [ >>x drop ] [ 1 bitand ] bi ;
PRIVATE>