next up previous index
Next: V136 Poisson Random Up: CERNLIB Previous: V130 Random Three-Dimensional

V135 Gamma or Chi-Square Random Numbers

Routine ID: V135
Author(s): F. James, K.S. KölbigLibrary: MATHLIB
Submitter: Submitted: 15.10.1994
Language: FortranRevised:

Function subprogram RANGAM generates a positive random number x according to the gamma distribution with parameter p>0, i.e., according to the density

P(t < x < t+dt) = {1Γ(p)} tp-1e-tdt.

A special case is the χ2 -distribution with N degrees of freedom

χ2(t < 2x < t+dt) = {12N Γ({12}N)} t{12}N-1 e-{12}t dt.

Structure:

FUNCTION subprogram
User Entry Names: RNGAMA
External References: RANLUX (V115), RNORMX (V120)

Usage:

In any arithmetic expression,

    RNGAMA(P)
has the value of a gamma-distributed random number, where P > 0 is of type REAL. The value of P may vary from call to call without influencing the efficiency.

Method:

For integral values of p ≤15 , the logarithm of the product of p uniform random numbers is used. For any value of p > 15, the Wilson-Hilferty approximation (a transformed normal distribution) is used. For all other p, Johnk's algorithm is used.

Notes:

The routine is fast for small integer values of p, and for p > 15, (one Gaussian random number and one square root, plus a few multiplications). Non-integral values of p < 15 are rather slow.

Examples:

    CHI2 = 2*RNGAMA(0.5*N)
sets CHI2 to a random number distributed as χ2 with N degrees of freedom.

V136


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995