# Exponential Random Numbers

Exponentially distributed pseudorandom numbers.

## Usage

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

#### exponential( lambda )

Returns a pseudorandom number drawn from an exponential distribution with rate parameter `lambda`.

``````var r = exponential( 7.9 );
// returns <number>
``````

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

``````var r = exponential( -2.0 );
// returns NaN

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

#### exponential.factory( [lambda, ][options] )

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

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

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

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

``````var rand = exponential.factory( 10.0 );

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

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

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

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

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

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

rand = exponential.factory( 4.5, {
'seed': 12345
});

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

#### exponential.NAME

The generator name.

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

#### exponential.PRNG

The underlying pseudorandom number generator.

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

#### exponential.SEED

The value used to seed `exponential()`.

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

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

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

## Examples

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

var seed;
var rand;
var i;

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

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