# Geometric Random Numbers

Geometric distributed pseudorandom numbers.

## Usage

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

#### geometric( p )

Returns a pseudorandom number drawn from a geometric distribution with success probability `p`.

``````var r = geometric( 0.8 );
// returns <number>
``````

If `p < 0` or `p > 1`, the function returns `NaN`.

``````var r = geometric( 3.14 );
// returns NaN

r = geometric( -0.5 );
// returns NaN
``````

If `p` is `NaN`, the function returns `NaN`.

``````var r = geometric( NaN );
// returns NaN
``````

#### geometric.factory( [p, ][options] )

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

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

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

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

``````var rand = geometric.factory( 0.6 );

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

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

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

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

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

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

var r = geometric( 0.9 );
// returns <number>

rand = geometric.factory( 0.2, {
'seed': 12345
});

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

#### geometric.NAME

The generator name.

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

#### geometric.PRNG

The underlying pseudorandom number generator.

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

#### geometric.SEED

The value used to seed `geometric()`.

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

// Generate pseudorandom values...
for ( i = 0; i < 100; i++ ) {
r = geometric( 20, 0.5 );
}

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

## Examples

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

var seed;
var rand;
var i;

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

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