Miss any of our Open RFC calls?Watch the recordings here! »

mersenne-twister

1.0.0 • Public • Published

Mersenne Twister

Mersenne Twister pseudorandom number generator.

Origin source (generator interface was changed)

Algorithm - http://en.wikipedia.org/wiki/Mersenne_twister

Installation

$ npm install mersenne-twister

Usage

var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister();
 
// Generates a random number on [0,1) real interval (same interval as Math.random)
generator.random();
 
// [0, 4294967295]
generator.random_int();
 
// [0,1]
generator.random_incl();
 
// (0,1)
generator.random_excl();
 
// [0,1) with 53-bit resolution
generator.random_long();
 
// [0, 2147483647]
generator.random_int31();

Seeding

If you want to use a specific seed in order to get a repeatable random sequence, pass an integer into the constructor:

var generator = new MersenneTwister(123);

and that will always produce the same random sequence.

Also you can do it on existing generator instance:

generator.init_seed(123);

License

See source

Install

npm i [email protected]

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar