IMSL C# Numerical Library

Random.NextNegativeBinomial Method 

Generate a pseudorandom number from a negative Binomial distribution.

public virtual int NextNegativeBinomial(
   double rk,
   double p
);

Parameters

rk
A double which specifies the negative binomial parameter, rk \gt 0.
p
A double which specifies the probability of success on each trial. It must be greater than machine precision and less than one.

Return Value

A int which specifies the pseudorandom number from a negative binomial distribution. If rk is an integer, the deviate can be thought of as the number of failures in a sequence of Bernoulli trials before rk successes occur.

Remarks

Method NextNegativeBinomial generates pseudorandom numbers from a negative Binomial distribution with parameters \rm rk and \rm p. \rm rk and \rm p must be positive and p must be less than 1. The probability function with (r = \rm rk and p = \rm p) is

f\left( x \right) = \left( 
            \begin{array}{c} r + x - 1 \\  x \\  \end{array} \right)\left( {1 - 
            p} \right)^r p^x

for x = 0, 1, 2, \ldots.

If r is an integer, the distribution is often called the Pascal distribution and can be thought of as modeling the length of a sequence of Bernoulli trials until r successes are obtained, where p is the probability of getting a success on any trial. In this form, the random variable takes values r, r + 1, r + 2, \ldots and can be obtained from the negative binomial random variable defined above by adding r to the negative binomial variable. This latter form is also equivalent to the sum of r geometric random variables defined as taking values 1, 2, 3, \ldots.

If rp/(1 - p) is less than 100 and (1 - p)^r is greater than the machine epsilon, NextNegativeBinomial uses the inverse CDF technique; otherwise, for each negative binomial deviate, NextNegativeBinomial generates a gamma (r, p/(1 - p)) deviate y and then generates a Poisson deviate with parameter y.

See Also

Random Class | Imsl.Stat Namespace | Example