factor/basis/random/mersenne-twister/mersenne-twister-tests.factor

30 lines
901 B
Factor
Raw Normal View History

USING: kernel math random namespaces make
random.mersenne-twister sequences tools.test math.order ;
2008-03-19 17:18:03 -04:00
IN: random.mersenne-twister.tests
: check-random ( max -- ? )
[ random 0 ] keep between? ;
2008-03-19 17:18:03 -04:00
[ t ] [ 100 [ drop 674 check-random ] all? ] unit-test
: randoms ( -- seq )
100 [ 100 random ] replicate ;
2008-03-19 17:18:03 -04:00
: test-rng ( seed quot -- )
2008-12-08 01:10:24 -05:00
[ <mersenne-twister> ] dip with-random ;
2008-03-19 17:18:03 -04:00
[ f ] [ 1234 [ randoms randoms = ] test-rng ] unit-test
2008-03-19 17:18:03 -04:00
[ 1333075495 ] [
0 [ 1000 [ drop random-generator get random-32* drop ] each random-generator get random-32* ] test-rng
2008-03-19 17:18:03 -04:00
] unit-test
[ 1575309035 ] [
0 [ 10000 [ drop random-generator get random-32* drop ] each random-generator get random-32* ] test-rng
2008-03-19 17:18:03 -04:00
] unit-test
[ 3 ] [ 101 [ 3 random-bytes length ] test-rng ] unit-test
[ 33 ] [ 101 [ 33 random-bytes length ] test-rng ] unit-test
[ t ] [ 101 [ 100 random-bits log2 90 > ] test-rng ] unit-test