IMSL C# Numerical Library

Random.NextBinomial Method 

Generate a pseudorandom number from a Binomial distribution.

public virtual int NextBinomial(
   int n,
   double p
);

Parameters

n
A int which specifies the number of Bernoulli trials.
p
A double which specifies the probability of success on each trial, 0 \lt p \lt 1.

Return Value

A int which specifies the pseudorandom number from a Binomial distribution.

Remarks

NextBinomial generates pseudorandom numbers from a Binomial distribution with parameters n and p. n and p must be positive, and p must be less than 1. The probability function (with n = n and p = p) is

f\left( x \right) = \left( {_x^n } 
            \right)p^x \left( {1 - p} \right)^{n - x}

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

The algorithm used depends on the values of n and p. If np \lt 10 or if p is less than a machine epsilon, the inverse CDF technique is used; otherwise, the BTPE algorithm of Kachitvichyanukul and Schmeiser (see Kachitvichyanukul 1982) is used. This is an acceptance/rejection method using a composition of four regions. (TPE equals Triangle, Parallelogram, Exponential, left and right.)

See Also

Random Class | Imsl.Stat Namespace | Example