randn

Standard normally distributed pseudorandom numbers.

Usage

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

randn()

Returns a standard normally distributed pseudorandom number.

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

randn.factory( [options] )

Returns a pseudorandom number generator for creating standard normally distributed random numbers.

var rand = randn.factory();

The function accepts the following options:

  • name: name of the underlying pseudorandom number generator which samples from the standard normal distribution. Default: 'improved-ziggurat'.
  • seed: pseudorandom number generator seed.

By default, the underlying pseudorandom number generator is improved-ziggurat. To use a different PRNG, set the name option.

var rand = randn.factory({
    'name': 'box-muller'
});

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

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

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

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

randn.NAME

The generator name.

var str = randn.NAME;
// returns 'standard-normal'

randn.PRNG

The underlying pseudorandom number generator.

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

randn.SEED

The value used to seed randn().

var rand;
var v;
var i;

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

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

Notes

  • Warning: the default underlying source of pseudorandom numbers may change in the future. If exact reproducibility is required, either explicitly specify a PRNG via the name option or use an underlying PRNG directly.

Examples

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

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() );
}