randomGamma¶
Generates pseudorandom numbers from a standard gamma distribution.
Synopsis¶
randomGamma (nRandom, a)
Required Arguments¶
- int
nRandom
(Input) - Number of random numbers to generate.
- float
a
(Input) - The shape parameter of the gamma distribution. This parameter must be positive.
Return Value¶
randomGamma
returns a vector of length nRandom
containing the
random standard gamma deviates.
Description¶
The function randomGamma
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 are generated. 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 randomGamma
and then
multiplying each entry in r
by b.
The Erlang distribution is a standard gamma distribution with the shape
parameter having a value equal to a positive integer; hence, randomGamma
generates pseudorandom deviates from an Erlang distribution with no
modifications required.
The function randomSeedSet
can be used to initialize the seed of the
random number generator. The function randomOption
can be used to select
the form of the generator.
Example¶
In this example, randomGamma
is used to generate five pseudorandom
deviates from a gamma (Erlang) distribution with shape parameter equal to
3.0.
from numpy import *
from pyimsl.math.randomGamma import randomGamma
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.writeMatrix import writeMatrix
randomSeedSet(123457)
a = 3.0
r = randomGamma(5, a)
writeMatrix("Gamma(3) random deviates", r)
Output¶
Gamma(3) random deviates
1 2 3 4 5
6.843 3.445 1.853 3.999 0.779