Improved Ziggurat Method

Standard normally distributed pseudorandom numbers using the Improved Ziggurat method.

Usage

var randn = require( '@stdlib/random/base/improved-ziggurat' );

randn()

Returns a standard normally distributed pseudorandom number.

var r = randn();
// returns <number>

randn.factory( [options] )

Returns a pseudorandom number generator (PRNG) for generating standard normally distributed pseudorandom numbers.

var rand = randn.factory();

The function accepts the following options:

  • prng: pseudorandom number generator for generating uniformly distributed pseudorandom numbers on the interval [0,1).
  • seed: pseudorandom number generator seed.

To use a custom PRNG as the underlying source of uniformly distributed pseudorandom numbers, set the prng option.

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

var rand = randn.factory({
    'prng': minstd.normalized
});

var r = rand();
// returns <number>

To seed a pseudorandom number generator, set the seed option.

var rand = randn.factory({
    'seed': 12345
});

var r = rand();
// returns <number>

randn.NAME

The generator name.

var str = randn.NAME;
// returns 'improved-ziggurat'

randn.PRNG

The underlying pseudorandom number generator for uniformly distributed numbers on the interval [0,1).

var prng = randn.PRNG;
// returns <Function>

randn.SEED

The value used to seed randn().

var rand;
var r;
var i;

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

// Generate the same pseudorandom values...
rand = randn.factory({
    'seed': randn.SEED
});
for ( i = 0; i < 100; i++ ) {
    r = rand();
}

If provided a PRNG for uniformly distributed numbers which does not have a SEED property, this value is null.

var rand = randn.factory({
    'prng': Math.random
});

var seed = rand.SEED;
// returns null

Examples

var randn = require( '@stdlib/random/base/improved-ziggurat' );

var seed;
var rand;
var i;

// Generate pseudorandom numbers...
for ( i = 0; i < 100; i++ ) {
    console.log( randn() );
}

// Create a new pseudorandom number generator...
seed = 1234;
rand = randn.factory({
    'seed': seed
});
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}

// Create another pseudorandom number generator using a previous seed...
rand = randn.factory({
    'seed': randn.SEED
});
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}

References