This guide is specifically for pseudo-random number generators (PRNGs) written in JavaScript, and tested in Mac OS X.
Homebrew
Run this in the Terminal to install Homebrew (site):
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Node.js
You can now use Homebrew to install Node.js (site):
brew install node
DieHarder
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.
The minimist package
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
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 the simple Park-Miller PRNG.
Make the file executable (chmod +x randout.js) then execute it and put its output into a file:
./randout.js > numbers.txt
And now you can test it with Dieharder:
dieharder -g 202 -f numbers.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!
You can now add more constructors for other PRNGs in randout.js. They just need a random method which returns a 32-bit
integer. To change which constructor is used, call the script with the --prng argument:
./randout.js --prng MersenneTwister > numbers.txt