next up previous index
Next: V110 Poisson Random Up: CERNLIB Previous: V108 Portable Gaussian

V109 Random Numbers in Gamma or Chisquare Distribution

Routine ID: V109
Author(s): J.F. Chamayou, F. JamesLibrary: MATHLIB
Submitter: Submitted: 01.07.1979
Language: FortranRevised:

OBSOLETE

Please note that this routine has been obsoleted in CNL 218. Users are advised not to use it any longer and to replace it in older programs. No maintenance for it will take place and it will eventually disappear.
Suggested replacement: RNGAMA (V135)

RANGAM generates positive random numbers x according to the gamma distribution with positive parameter p, i.e., according to the density

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

A special case of this distribution is the χ2 -distribution.

Structure:

FUNCTION subprogram
User Entry Names: RANGAM
External References: NORRAN (V101), RNDM (V104), NRAN (V105)

Usage:

    Z = RANGAM(P)
sets Z to a gamma-distributed random number for any real parameter P > 0 . The value of P may vary from call to call without infuencing 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*RANGAM(0.5*ND)
sets CHI2 to a random number distributed as χ2 with ND degrees of freedom.

V110


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