Rayleigh Random Numbers

Rayleigh distributed pseudorandom numbers.

Usage

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

rayleigh( sigma )

Returns a pseudorandom number drawn from a Rayleigh distribution with scale parameter sigma.

var r = rayleigh( 2.5 );
// returns <number>

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

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

r = rayleigh( NaN );
// returns NaN

rayleigh.factory( [sigma, ][options] )

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

var rand = rayleigh.factory();

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

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

var rand = rayleigh.factory( 10.0 );

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

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

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

var rand = rayleigh.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 = rayleigh.factory({
    'seed': 12345
});

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

rand = rayleigh.factory( 3.0, {
    'seed': 12345
});

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

rayleigh.NAME

The generator name.

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

rayleigh.PRNG

The underlying pseudorandom number generator.

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

rayleigh.SEED

The value used to seed rayleigh().

var rand;
var r;
var i;

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

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

Examples

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

var seed;
var rand;
var i;

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

// Create a new pseudorandom number generator...
seed = 1234;
rand = rayleigh.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 = rayleigh.factory( 0.5, {
    'seed': rayleigh.SEED
});
console.log( '\nseed: %d', rayleigh.SEED );
for ( i = 0; i < 100; i++ ) {
    console.log( rand() );
}