Generates pseudorandom numbers from a Poisson distribution.
#include <imsl.h>
int *imsl_random_poisson (int n_random, float theta, ¼, 0)
int n_random
(Input)
Number of random numbers to generate.
float theta
(Input)
Mean of the Poisson distribution. The argument theta must be
positive.
If no optional arguments are used, imsl_random_poisson returns a pointer to a vector of length n_random containing the random Poisson deviates. To release this space, use free.
#include <imsl.h>
int
*imsl_random_poisson (int
n_random,
float
theta,
IMSL_RETURN_USER, int r[],
0)
IMSL_RETURN_USER, int r[]
(Output)
If specified, the vector of length n_random of random
Poisson deviates is returned in the user-provided array r.
The function imsl_random_poisson
generates pseudorandom numbers from
a Poisson distribution with positive
mean theta.
The probability function
(with θ = theta)
is
f(x) = (e-qqx)/x!, for x = 0, 1,2, ¼
If theta is less than 15, imsl_random_poisson uses an inverse CDF method; otherwise, the PTPE method of Schmeiser and Kachitvichyanukul (1981) (see also Schmeiser 1983) is used. The PTPE method uses a composition of four regions, a triangle, a parallelogram, and two negative exponentials. In each region except the triangle, acceptance/rejection is used. The execution time of the method is essentially insensitive to the mean of the Poisson.
The function imsl_random_seed_set can be used to initialize the seed of the random number generator. The function imsl_random_option can be used to select the form of the generator.
In this example, imsl_random_poisson is used to generate five pseudorandom deviates from a Poisson distribution with mean equal to 0.5.
#include <imsl.h>
#define
N_RANDOM 5
void
main()
{
int *r;
int seed =
123457;
float theta =
0.5;
imsl_random_seed_set
(seed);
r = imsl_random_poisson (N_RANDOM, theta,
0);
imsl_i_write_matrix ("Poisson(0.5) random deviates",
1, 5, r, 0);
}
Poisson(0.5) random
deviates
1 2
3 4 5
2
0 1 0 1
|
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |