# Erlang Random Numbers

Erlang distributed pseudorandom numbers.

## Usage

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

#### erlang( k, lambda )

Returns a pseudorandom number drawn from a Erlang distribution with parameters `k` (shape parameter) and `lambda` (rate parameter).

``````var r = erlang( 2, 5.0 );
// returns <number>
``````

If `k` is not a positive integer, the function returns `NaN`.

``````var r = erlang( 2.2, 1.0 );
// returns NaN
``````

If `lambda <= 0`, the function returns `NaN`.

``````var r = erlang( 2, -2.0 );
// returns NaN
``````

If either `k` or `lambda` is `NaN`, the function returns `NaN`.

``````var r = erlang( NaN, 5.0 );
// returns NaN

r = erlang( 2, NaN );
// returns NaN
``````

#### erlang.factory( [k, lambda, ][options] )

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

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

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

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

``````// Draw from Erlang( 2, 1.5 ) distribution:
var rand = erlang.factory( 2, 1.5 );

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

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

If not provided `k` and `lambda`, the returned generator requires that both parameters be provided at each invocation.

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

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

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

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

rand = erlang.factory( 2, 3.0, {
'seed': 12345
});

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

#### erlang.NAME

The generator name.

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

#### erlang.PRNG

The underlying pseudorandom number generator.

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

#### erlang.SEED

The value used to seed `erlang()`.

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

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

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

## Examples

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

var seed;
var rand;
var i;

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

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