MINSTD

A linear congruential pseudorandom number generator (LCG) based on Park and Miller.

Usage

var minstd = require( '@stdlib/random/base/minstd' );

minstd()

Returns a pseudorandom integer on the interval [1, 2147483646].

var v = minstd();
// returns <number>

minstd.normalized()

Returns a pseudorandom number on the interval [0,1).

var v = minstd.normalized();
// returns <number>

minstd.factory( [seed] )

Returns a linear congruential pseudorandom number generator (LCG).

var rand = minstd.factory();

By default, a random integer is used to seed the returned generator. To seed the generator, provide an integer on the interval [1, 2147483646].

var rand = minstd.factory( 1234 );

var v = rand();
// returns 20739838

minstd.NAME

The generator name.

var str = minstd.NAME;
// returns 'minstd'

minstd.SEED

The value used to seed minstd().

var rand;
var v;
var i;

// Generate pseudorandom values...
for ( i = 0; i < 100; i++ ) {
v = minstd();
}

// Generate the same pseudorandom values...
rand = minstd.factory( minstd.SEED );
for ( i = 0; i < 100; i++ ) {
v = rand();
}

minstd.MIN

Minimum possible value.

var min = minstd.MIN;
// returns 1

minstd.MAX

Maximum possible value.

var max = minstd.MAX;
// returns 2147483646
• The generator has a period of approximately 2.1e9 (see Numerical Recipes in C, 2nd Edition, p. 279).
• An LCG is fast and uses little memory. On the other hand, because the generator is a simple linear congruential generator, the generator has recognized shortcomings. By today's PRNG standards, the generator's period is relatively short. More importantly, the "randomness quality" of the generator's output is lacking. These defects make the generator unsuitable, for example, in Monte Carlo simulations and in cryptographic applications. For more on the advantages and disadvantages of LCGs, see Wikipedia.