# Chi-square Random Numbers

Chi-square distributed pseudorandom numbers.

## Usage

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

#### chisquare( k )

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

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

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

``````var r = chisquare( -2 );
// returns NaN

r = chisquare( NaN );
// returns NaN
``````

#### chisquare.factory( [k, ][options] )

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

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

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

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

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

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

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

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

#### chisquare.NAME

The generator name.

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

#### chisquare.PRNG

The underlying pseudorandom number generator.

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

#### chisquare.SEED

The value used to seed `chisquare()`.

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

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

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

## Examples

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

var seed;
var rand;
var i;

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

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