RNGAM
Generates pseudorandom numbers from a standard gamma distribution.
Required Arguments
A — The shape parameter of the gamma distribution. (Input)
This parameter must be positive.
R — Vector of length NR containing the random standard gamma deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (R,1).
FORTRAN 90 Interface
Generic: CALL RNGAM (A, R [, …])
Specific: The specific interface names are S_RNGAM and D_RNGAM.
FORTRAN 77 Interface
Single: CALL RNGAM (NR, A, R)
Double: The double precision name is DRNGAM.
Description
Routine RNGAM generates pseudorandom numbers from a gamma distribution with shape parameter a and unit scale parameter. The probability density function is
Various computational algorithms are used depending on the value of the shape parameter
a. For the special case of
a = 0.5, squared and halved normal deviates are used; and for the special case of
a = 1.0, exponential deviates (from IMSL routine
RNEXP) are used. Otherwise, if
a is less than 1.0, an acceptance‑rejection method due to Ahrens, described in Ahrens and Dieter (1974), is used; if
a is greater than 1.0, a ten‑region rejection procedure developed by Schmeiser and Lal (1980) is used.
Deviates from the two‑parameter gamma distribution with shape parameter a and scale parameter b can be generated by using RNGAM and then multiplying each entry in R by b. The following statements (in single precision) would yield random deviates from a gamma (a, b) distribution.
CALL RNGAM (NR, A, R)
CALL SSCAL (NR, B, R, 1)
The Erlang distribution is a standard gamma distribution with the shape parameter having a value equal to a positive integer; hence, RNGAM generates pseudorandom deviates from an Erlang distribution with no modifications required.
Comments
The routine
RNSET can be used to initialize the seed of the random number generator. The routine
RNOPT can be used to select the form of the generator.
Example
In this example, RNGAM is used to generate five pseudorandom deviates from a gamma (Erlang) distribution with shape parameter equal to 3.0.
USE RNGAM_INT
USE UMACH_INT
USE RNSET_INT
IMPLICIT NONE
INTEGER NR
PARAMETER (NR=5)
!
INTEGER ISEED, NOUT
REAL A, R(NR)
!
CALL UMACH (2, NOUT)
A = 3.0
ISEED = 123457
CALL RNSET (ISEED)
CALL RNGAM (A, R)
WRITE (NOUT,99999) R
99999 FORMAT (' Gamma(3) random deviates: ', 5F8.4)
END
Output
Gamma(3) random deviates: 6.8428 3.4452 1.8535 3.9992 0.7794