module:MersenneTwister

module:MersenneTwister

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.

Constructor

new (require("MersenneTwister"))(seedopt)

Source:
Version:
  • 0.2.3
Since:
  • 0.1.0
Author:
License:
  • See the attached LICENSE file.

Instantiates a new Mersenne Twister.

Parameters:
Name Type Attributes Description
seed number <optional>

The initial seed value.

Methods

int() → {number}

Source:
Since:
  • 0.1.0

Generates a random unsigned 32-bit integer.

Returns:
Type
number

int31() → {number}

Source:
Since:
  • 0.1.0

Generates a random unsigned 31-bit integer.

Returns:
Type
number

random() → {number}

Source:
Since:
  • 0.2.0

Generates a random real in the interval [0;1[ with 32-bit resolution.

Same as .rnd() method - for consistency with Math.random() interface.

Returns:
Type
number

real() → {number}

Source:
Since:
  • 0.1.0

Generates a random real in the interval [0;1] with 32-bit resolution.

Returns:
Type
number

realx() → {number}

Source:
Since:
  • 0.1.0

Generates a random real in the interval ]0;1[ with 32-bit resolution.

Returns:
Type
number

rnd() → {number}

Source:
Since:
  • 0.1.0

Generates a random real in the interval [0;1[ with 32-bit resolution.

Returns:
Type
number

rndHiRes() → {number}

Source:
Since:
  • 0.1.0

Generates a random real in the interval [0;1[ with 53-bit resolution.

Returns:
Type
number

seed(seed)

Source:
Since:
  • 0.1.0

Initializes the state vector by using one unsigned 32-bit integer "seed", which may be zero.

Parameters:
Name Type Description
seed number

The seed value.

seedArray(vector)

Source:
Since:
  • 0.1.0

Initializes the state vector by using an array key[] of unsigned 32-bit integers of the specified length. If length is smaller than 624, then each array of 32-bit integers gives distinct initial state vector. This is useful if you want a larger seed space than 32-bit word.

Parameters:
Name Type Description
vector array

The seed vector.