Node.js Mersenne Twister random number generator module

jwatte's picture

I made a Node.js module. It's a packaging and slight update of the JavaScript implementation of the Mersenne Twister random number generator (which is a really high quality generator, as well as pretty fast).

I'm hoping you can soon get it with npm:

$ npm install mersenne
$

Usage is simple:

r = require('mersenne');
r.rand(N) <-- return a random number between 0 and N-1, inclusive

You can also do more advanced things, like creating multiple instances, return random floating-point numbers, etc.

Exported functions:

Convenient defaults:
rand(N): generate random number between 0 and N-1 from default generator
seed(N): seed the default random number generator
seed_array(A): seed the default random number generator better, using array of numbers
 
Specific generator instance control:
new MersenneTwister19937(): constructor for a new generator
    init_genrand(N) -- seed with a number
    init_by_array(A) -- seed with an array of numbers
    genrand_int32() -- random number between 0 and 0xffffffff inclusive
    genrand_int31() -- random number between 0 and 0x7fffffff inclusive
    genrand_real1() -- random number between 0.0 and 1.0 inclusive
    genrand_real2() -- random number between 0.0 (inclusive) and 1.0 (exclusive)
    genrand_real3() -- random number between 0.0 and 1.0 (exclusive)
    genrand_res53() -- random number with 53 bits of randomness