Testing RNGs with Dieharder
Run this in the Terminal to install Homebrew (site):
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
You can now use Homebrew to install Node.js (site):
brew install node
Homebrew also lets you install Dieharder, the tool that tests RNGs (site):
brew install dieharder
A directory for your testing
Create a directory which you'll use for testing PRNGs. This is where we'll put scripts and data.
A very useful package for parsing arguments which I use for the script below. Go into the testing directory and install it with NPM:
npm install minimist
Communicating with Dieharder
Dieharder can take a file as an input, so we'll use a simple Node.js script for generating a dump of random numbers. See
randout.js below for a template file that implements an integer version of the built-in RNG as well as the very simple
Make the file executable (
chmod +x randout.js) then execute it and put its output into a file:
./randout.js > math.random.txt
Note: By default this will create 10,000,000 random numbers. That takes time and space, but is necessary for an accurate test.
And now you can test it with Dieharder:
dieharder -g 202 -f math.random.txt -a
You can read more about the
dieharder tool on the Dieharder homepage, but this will run all tests on that file. Note: It will take some time!
Testing more PRNGs
You can now add more constructors for other PRNGs in
randout.js. They just need a
next method which returns an integer.
To change which constructor is used, call the script with the
./randout.js --prng ParkMiller > park-miller.txt