Hasard contains many tests to detect implementation bugs. To run all tests, type ”./run_tests.sh”. The most important test program is python/test_hasard.py.
You can also use the following programs to check random number generators quality: dieharder, ENT, TestU01.
- Test entropy: python/file_info.py
- Use ENT program: python/ent.py
- Benchmark: benchmark.c
- Manual visual check:
test_hasard.py has many test suites applied on each generator. The script have command line options, the most useful are:
- –slow / –very-slow: Slower tests, but test more cases
- -r REPEAT: repeaet each test suite REPEAT times
- -v: verbose
You can also test only one generator using its name, eg. “test_hasard.py arcfour”. Or you can run only some test suites using -k option, eg. “test_haasrd.py -k fork” runs all fork tests.
“init” test ensures that if two differents generators are created, the state is different. “reseed” is similar: it checks also for duplicate state, but after a “reseed” (call hasard_reseed() function). Both tests use the options –slow and –very-slow to choose how much tests are used:
- Default: 10
- –slow: 2^10
- –very-slow: 2^20
dieharder and ENT¶
python/dieharder.py and python/ent.py require an Hasard data file. Use python/gen_files.py program to create such file. Examples:
./python/gen_files.py --rng=@fast --count=2**20 fast_ticks.dat ./python/gen_files.py --rng=@fast --op=ulong --min=0 --max=2**16-1 fast_ulong16.dat
Dieharder requires at least 2^24 numbers and is very slow (can take more than one hour).
ENT output is not really revelant, use Dieharder, or better TestU01.
TestU01 is a test suite written by Pierre l’Ecuyer: http://www.iro.umontreal.ca/~simardr/testu01/tu01.html
Example: ”./tools/testu01 @fast SmallCrush”.
Except SmallCrush and FIPS_140_2, most test suites are very slow (takes more than 10 hours).
Test RNG quality¶
- TUT01 by Pierre l’Écuyer and Richard Simard
- DieHarder (2007) by Robert G. Brown
- Diehard, Battery of Tests of Randomness (1995) by George Marsaglia, dedicated to RNG using 32 bits unsigned integer
- rngtest from the rng-tools package FIPS 140-2 (2001-10-10)
- NIST 800-90 (2007): Recommendation for Random Number Generation Using Deterministic Random Bit Generators
- Be careful with Dual_EC_DRBG: read The Strange Story of Dual_EC_DRBG by Bruce Schneier
- NIST 800-22 (2001): A statistical test suite for random and pseudorandom number generators for cryptographic applications
- Software Generation of Practically Strong Random Numbers (1998, updated in 2000) by Peter Gutmann
- [[ftp://ftp.isi.edu/in-notes/rfc1750.txt|RFC 1750: Randomness Recommendations for Security]] (1994) by D. Eastlake, S. Crocker and J. Schiller
- Testing random number generators (1992) by Pierre L’Ecuyer
- Random Number Generation Technical Working Group from the NIST