F Random Numbers

F distributed pseudorandom numbers.

Usage

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

f( d1, d2 )

Returns a pseudorandom number drawn from an F distribution with parameters d1 (degrees of freedom) and d2 (degrees of freedom).

var r = f( 2.0, 5.0 );
// returns <number>

If d1 <= 0 or d2 <= 0, the function returns NaN.

var r = f( 2.0, -2.0 );
// returns NaN

r = f( -2.0, 2.0 );
// returns NaN

If d1 or d2 is NaN, the function returns NaN.

var r = f( NaN, 5.0 );
// returns NaN

r = f( 2.0, NaN );
// returns NaN

f.factory( [d1, d2, ][options] )

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

var rand = f.factory();

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

If provided d1 and d2, the returned generator returns random variates from the specified distribution.

// Draw from F( 1.5, 1.5 ) distribution:
var rand = f.factory( 1.5, 1.5 );

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

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

If not provided d1 and d2, the returned generator requires that both parameters be provided at each invocation.

var rand = f.factory();

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

r = rand( 3.14, 2.25 );
// 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 = f.factory({
    'seed': 12345
});

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

rand = f.factory( 1.0, 2.0, {
    'seed': 12345
});

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

f.NAME

The generator name.

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

f.PRNG

The underlying pseudorandom number generator.

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

f.SEED

The value used to seed f().

var rand;
var r;
var i;

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

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

Examples

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

var seed;
var rand;
var i;

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

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