Chi Random Numbers

Chi distributed pseudorandom numbers.

Usage

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

chi( k )

Returns a pseudorandom number drawn from a chi distribution with degrees of freedom k.

var r = chi( 2 );
// returns <number>

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

var r = chi( -2 );
// returns NaN

r = chi( NaN );
// returns NaN

chi.factory( [k, ][options] )

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

var rand = chi.factory();

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

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

var rand = chi.factory( 1.0 );

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

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

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

var rand = chi.factory();

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

var r = rand( 3 );
// returns 1.1430117595342395

rand = chi.factory( 3, {
    'seed': 12345
});

r = rand();
// returns 1.1430117595342395

chi.NAME

The generator name.

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

chi.PRNG

The underlying pseudorandom number generator.

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

chi.SEED

The value used to seed chi().

var rand;
var r;
var i;

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

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

Examples

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

var seed;
var rand;
var i;

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

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