Usage
var negativeBinomial = require( '@stdlib/random-base-negative-binomial' );
negativeBinomial( r, p )
Returns a pseudorandom number drawn from a negative binomial distribution with parameters r
(number of successes until experiment is stopped) and p
(success probability).
var r = negativeBinomial( 20, 0.8 );
If r
or p
is NaN
, the function returns NaN
.
var r = negativeBinomial( NaN, 0.4 );
r = negativeBinomial( 20, NaN );
If p
is not in the interval (0,1)
(exclusive), the function returns NaN
.
var r = negativeBinomial( 10, 1.1 );
r = negativeBinomial( 10, 1.0 );
r = negativeBinomial( 10, 0.0 );
negativeBinomial.factory( [r, p, ][options] )
Returns a pseudorandom number generator (PRNG) for generating pseudorandom numbers drawn from a negative binomial distribution.
var rand = negativeBinomial.factory();
var r = rand( 20, 0.3 );
If provided r
and p
, the returned generator returns random variates from the specified distribution.
var rand = negativeBinomial.factory( 10, 0.8 );
var r = rand();
r = rand();
If not provided r
and p
, the returned generator requires that both parameters be provided at each invocation.
var rand = negativeBinomial.factory();
var r = rand( 20, 0.8 );
r = rand( 123, 0.21 );
The function accepts the following options
:
- prng: pseudorandom number generator for generating uniformly distributed pseudorandom numbers on the interval
[0,1)
. If provided, the function ignores both the state
and seed
options. In order to seed the returned pseudorandom number generator, one must seed the provided prng
(assuming the provided prng
is seedable). - seed: pseudorandom number generator seed.
- state: a
Uint32Array
containing pseudorandom number generator state. If provided, the function ignores the seed
option. - copy:
boolean
indicating whether to copy a provided pseudorandom number generator state. Setting this option to false
allows sharing state between two or more pseudorandom number generators. Setting this option to true
ensures that a returned generator has exclusive control over its internal state. Default: true
.
To use a custom PRNG as the underlying source of uniformly distributed pseudorandom numbers, set the prng
option.
var minstd = require( '@stdlib/random-base-minstd' );
var rand = negativeBinomial.factory({
'prng': minstd.normalized
});
var r = rand( 8, 0.9 );
To seed a pseudorandom number generator, set the seed
option.
var rand1 = negativeBinomial.factory({
'seed': 12345
});
var r1 = rand1( 8, 0.9 );
var rand2 = negativeBinomial.factory( 8, 0.9, {
'seed': 12345
});
var r2 = rand2();
var bool = ( r1 === r2 );
To return a generator having a specific initial state, set the generator state
option.
var rand;
var bool;
var r;
var i;
for ( i = 0; i < 1000; i++ ) {
r = negativeBinomial( 8, 0.9 );
}
rand = negativeBinomial.factory({
'state': negativeBinomial.state
});
bool = ( rand( 8, 0.9 ) === negativeBinomial( 8, 0.9 ) );
negativeBinomial.NAME
The generator name.
var str = negativeBinomial.NAME;
negativeBinomial.PRNG
The underlying pseudorandom number generator.
var prng = negativeBinomial.PRNG;
negativeBinomial.seed
The value used to seed negativeBinomial()
.
var rand;
var r;
var i;
for ( i = 0; i < 100; i++ ) {
r = negativeBinomial( 20, 0.5 );
}
rand = negativeBinomial.factory( 20, 0.5, {
'seed': negativeBinomial.seed
});
for ( i = 0; i < 100; i++ ) {
r = rand();
}
If provided a PRNG for uniformly distributed numbers, this value is null
.
var rand = negativeBinomial.factory({
'prng': Math.random
});
var seed = rand.seed;
negativeBinomial.seedLength
Length of generator seed.
var len = negativeBinomial.seedLength;
If provided a PRNG for uniformly distributed numbers, this value is null
.
var rand = negativeBinomial.factory({
'prng': Math.random
});
var len = rand.seedLength;
negativeBinomial.state
Writable property for getting and setting the generator state.
var r = negativeBinomial( 20, 0.5 );
r = negativeBinomial( 20, 0.5 );
var state = negativeBinomial.state;
r = negativeBinomial( 20, 0.5 );
r = negativeBinomial( 20, 0.5 );
negativeBinomial.state = state;
r = negativeBinomial( 20, 0.5 );
r = negativeBinomial( 20, 0.5 );
If provided a PRNG for uniformly distributed numbers, this value is null
.
var rand = negativeBinomial.factory({
'prng': Math.random
});
var state = rand.state;
negativeBinomial.stateLength
Length of generator state.
var len = negativeBinomial.stateLength;
If provided a PRNG for uniformly distributed numbers, this value is null
.
var rand = negativeBinomial.factory({
'prng': Math.random
});
var len = rand.stateLength;
negativeBinomial.byteLength
Size (in bytes) of generator state.
var sz = negativeBinomial.byteLength;
If provided a PRNG for uniformly distributed numbers, this value is null
.
var rand = negativeBinomial.factory({
'prng': Math.random
});
var sz = rand.byteLength;
negativeBinomial.toJSON()
Serializes the pseudorandom number generator as a JSON object.
var o = negativeBinomial.toJSON();
If provided a PRNG for uniformly distributed numbers, this method returns null
.
var rand = negativeBinomial.factory({
'prng': Math.random
});
var o = rand.toJSON();