Fréchet Random Numbers

Fréchet distributed pseudorandom numbers.

Usage

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

frechet( alpha, s, m )

Returns a pseudorandom number drawn from a Fréchet distribution with parameters `alpha` (shape), `s` (scale), and `m` (location).

``````var r = frechet( 2.0, 5.0, 3.33 );
// returns <number>
``````

If either `alpha`, `s`, or `m` is `NaN`, the function returns `NaN`.

``````var r = frechet( NaN, 1.0, 0.5 );
// returns NaN

r = frechet( 1.0, NaN, 2.42 );
// returns NaN

r = frechet( 7.0, 10.0, NaN );
// returns NaN
``````

If provided `alpha <= 0`, the function returns `NaN`.

``````var y = frechet( 0.0, 3.0, 2.0 );
// returns NaN

y = frechet( -1.0, 2.0, 2.0 );
// returns NaN
``````

If provided `s <= 0`, the function returns `NaN`.

``````var y = frechet( 1.0, 0.0, 2.0 );
// returns NaN

y = frechet( 1.0, -1.0, 2.0 );
// returns NaN
``````

frechet.factory( [alpha, s, m, ][options] )

Returns a pseudorandom number generator (PRNG) for generating pseudorandom numbers drawn from a Fréchet distribution.

``````var rand = frechet.factory();

var r = rand( 2.0, 1.0, 0.5 );
// returns <number>
``````

If provided `alpha`, `s`, and `m`, the returned generator returns random variates from the specified distribution.

``````var rand = frechet.factory( -2.0, 2.0, 1.0 );

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

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

If not provided `alpha`, `s`, and `m`, the returned generator requires that all three parameters be provided at each invocation.

``````var rand = frechet.factory();

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

r = rand( 2.0, 8.0, 0.1 );
// 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 = frechet.factory({
'seed': 12345
});

var r = rand( 2.0, 4.0, 3.0 );
// returns ~17.143

rand = frechet.factory( 2.0, 4.0, 3.0, {
'seed': 12345
});

r = rand();
// returns ~17.143
``````

frechet.NAME

The generator name.

``````var str = frechet.NAME;
// returns 'frechet'
``````

frechet.PRNG

The underlying pseudorandom number generator.

``````var prng = frechet.PRNG;
// returns <Function>
``````

frechet.SEED

The value used to seed `frechet()`.

``````var rand;
var r;
var i;

// Generate pseudorandom values...
for ( i = 0; i < 100; i++ ) {
r = frechet( 4.0, 10.0 );
}

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

Examples

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

var seed;
var rand;
var i;

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

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