A standalone, pure JavaScript implementation of the Mersenne Twister pseudo random number generator. Compatible with Node.js, requirejs and browser environments. Packages are available for npm, Jam and Bower.
It would be useful if the MersenneTwister had a .random() method that was compliant with the Math.random() return interval, [0:1[, and resolution, 32 bit.
This is useful for debugging code that uses Math.random() calls, because it makes the behavior predictable. Other uses might be possible, but here's the usage pattern I envision:
varrandomBoolean=function(rng)// rng: an *optional* random number generator{// Determine if a random number generator with .random() method was passed.// Subsequent rng.random() calls will be Math.random() if no rng was passed.if(rng===undefined||typeofrng.random!=='function')rng=Math;returnrng.random()>=0.5;// return random boolean value}varmt=newMersenneTwister(123);while(randomBoolean(mt))// use seeded generator mt{console.log('this will be printed twice on every execution');}while(randomBoolean())// use default Math.random(){console.log('nondeterministic execution');}