A JavaScript implementation of the Mersenne Twister pseudo-random number generator.
Installation (via npm)
$ npm install @dsibilly/mersenne-twister
Get an instance of RNG:
const MersenneTwister = require('@dsibilly/mersenne-twister'),
rng = = new MersenneTwister();
...or with ES2015+ import
:
import MersenneTwister from '@dsibilly/mersenne-twister';
const rng = new MersenneTwister();
const rng2 = new MersenneTwister(4567),
rng3 = new MersenneTwister([
// You can also seed with an array of values
123,
456,
789
]);
Generate a random 32-bit integer:
const result = rng.randomInt();
Generate a random 31-bit integer::
const result = rng.randomInt31();
Generate a random number between 0 and 1, exclusive (e.g. 0 < n < 1):
const result = rng.randomExclusive();
Generate a random number where 0 <= n < 1:
const result = rng.random();
Generate a random number between 0 and 1, inclusive (e.g. 0 <= n <= 1):
const result = rng.randomInclusive();
Generate a random 53-bit number, 0 <= n <= 1:
const result = rng.randomLong();