Generates pseudorandom numbers from a standard gamma distribution.
#include <imsls.h>
float *imsls_f_random_gamma (int n_random, float a, ..., 0)
The type double function is imsls_d_random_gamma.
int n_random
(Input)
Number of random numbers to generate.
float a
(Input)
Shape parameter of the gamma distribution. This parameter must be
positive.
An array of length n_random containing the random standard gamma deviates.
#include <imsls.h>
float
*imsls_f_random_gamma (int
n_random, float a,
IMSLS_RETURN_USER, float
r[],
0)
IMSLS_USER_RETURN, float r[]
(Output)
User-supplied array of length n_random containing
the random standard gamma deviates.
Function imsls_f_random_gamma 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; 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 imsls_f_random_gamma 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.
float *r;
r =
imsls_f_random_gamma(n_random, a, 0);
for
(i=0; i<n_random; i++) *(r+i) *= b;
The Erlang distribution is a standard gamma distribution with the shape parameter having a value equal to a positive integer; hence, imsls_f_random_gamma generates pseudorandom deviates from an Erlang distribution with no modifications required.
Function imsls_random_seed_set can be used to initialize the seed of the random number generator; function imsls_random_option can be used to select the form of the generator.
In this example, imsls_f_random_gamma generates five pseudorandom deviates from a gamma (Erlang) distribution with shape parameter equal to 3.0.
#include <imsls.h>
void
main()
{
int seed =
123457;
int n_random =
5;
float a =
3.0;
float
*r;
imsls_random_seed_set(seed);
r = imsls_f_random_gamma(n_random, a, 0);
imsls_f_write_matrix("Gamma(3) random deviates", 1, n_random, r,
0);
}
Gamma(3) random deviates
1
2
3
4
5
6.843
3.445
1.853 3.999
0.779
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |