fix random for real. is there redundant math here?

db4
Doug Coleman 2008-09-09 17:07:32 -05:00
parent d72114fcce
commit 24642501e7
2 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,5 @@
USING: random sequences tools.test kernel math math.functions ;
USING: random sequences tools.test kernel math math.functions
sets ;
IN: random.tests
[ 4 ] [ 4 random-bytes length ] unit-test
@ -12,3 +13,5 @@ IN: random.tests
[ t ] [ 10000 [ 0 [ drop 187 random + ] reduce ] keep / 2 * 187 10 ~ ] unit-test
[ t ] [ 10000 [ 0 [ drop 400 random + ] reduce ] keep / 2 * 400 10 ~ ] unit-test
[ t ] [ 1000 [ 400 random ] replicate prune length 256 > ] unit-test

View File

@ -36,10 +36,9 @@ M: f random-32* ( obj -- * ) no-random-number-generator ;
: random ( seq -- elt )
[ f ] [
[
length [
log2 8 + 8 /i
random-bytes byte-array>bignum
] keep mod
length dup log2 7 + 8 /i 1+ random-bytes
[ length 3 shift 2^ ] [ byte-array>bignum ] bi
swap / * >integer
] keep nth
] if-empty ;