Author(s): F. James, K.S. Kölbig | Library: MATHLIB |
Submitter: | Submitted: 15.10.1994 |
Language: Fortran | Revised: |
Function subprogram RANGAM generates a positive random number x according to the gamma distribution with parameter p>0, i.e., according to the density
A special case is the -distribution with N degrees of freedom
Structure:
FUNCTION subprogram
User Entry Names: RNGAMA
External References: RANLUX, RNORMX
Usage:
In any arithmetic expression,
RNGAMA(P)has the value of a gamma-distributed random number, where is of type REAL. The value of P may vary from call to call without influencing the efficiency.
Method:
For integral values of , 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 with N degrees of freedom.