Poisson Random Numbers

Poisson distributed pseudorandom numbers.

Usage

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

poisson( lambda )

Returns a pseudorandom number drawn from a Poisson distribution with mean parameter lambda.

var r = poisson( 7.9 );
// returns <number>

If lambda <= 0 or lambda is NaN, the function returns NaN.

var r = poisson( -2.0 );
// returns NaN

r = poisson( NaN );
// returns NaN

poisson.factory( [lambda, ][options] )

Returns a pseudorandom number generator (PRNG) for generating pseudorandom numbers drawn from a Poisson distribution.

var rand = poisson.factory();

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

If provided lambda, the returned generator returns random variates from the specified distribution.

var rand = poisson.factory( 10.0 );

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

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

If not provided lambda, the returned generator requires that lambda be provided at each invocation.

var rand = poisson.factory();

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

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

The function accepts the following options:

  • seed: pseudorandom number generator seed.

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

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

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

rand = poisson.factory( 4.5, {
    'seed': 12345
});

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

poisson.NAME

The generator name.

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

poisson.PRNG

The underlying pseudorandom number generator.

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

poisson.SEED

The value used to seed poisson().

var rand;
var r;
var i;

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

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

Examples

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

var seed;
var rand;
var i;

// Generate pseudorandom numbers...
console.log( '\nseed: %d', poisson.SEED );
for ( i = 0; i < 100; i++ ) {
    console.log( poisson( 8.0 ) );
}

// Create a new pseudorandom number generator...
seed = 1234;
rand = poisson.factory( 0.8, {
    'seed': seed
});
console.log( '\nseed: %d', seed );
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}

// Create another pseudorandom number generator using a previous seed...
rand = poisson.factory( 8.0, {
    'seed': poisson.SEED
});
console.log( '\nseed: %d', poisson.SEED );
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}

References

  • Knuth, Donald E. 1997. The Art of Computer Programming, Volume 2 (3rd Ed.): Seminumerical Algorithms. Boston, MA, USA: Addison-Wesley Longman Publishing Co., Inc.
  • Hörmann, W. 1993. "The transformed rejection method for generating Poisson random variables." Insurance: Mathematics and Economics 12 (1): 39–45. doi:10.1016/0167-6687(93)90997-4.