Generates pseudorandom numbers from a geometric distribution.
#include <imsls.h>
int *imsls_f_random_geometric (int n_random, float p, ..., 0)
The type double function is imsls_d_random_geometric.
int n_random
(Input)
Number of random numbers to generate.
float p
(Input)
Probability of succes on each trial. Parameter p must be positive and
less than 1.0.
An integer array of length n_random containing the random geometric deviates.
#include <imsls.h>
int
*imsls_f_random_geometric (int n_random,
float
p,
IMSLS_RETURN_USER,
int ir[],
0)
IMSLS_RETURN_USER, int ir[]
(Output)
User-supplied integer array of length n_random containing
the random geometric deviates.
Function imsls_f_random_geometric generates pseudorandom numbers from a geometric distribution with parameter P, where P is the probability of getting a success on any trial. A geometric deviate can be interpreted as the number of trials until the first success (including the trial in which the first success is obtained). The probability function is
f(x) = P(1 − P)x−1
for x = 1, 2, … and 0 < P < 1.
The geometric distribution as defined above has mean 1/P.
The i-th geometric deviate is generated as the smallest integer not less than (log (Ui))/(log (1 − P)), where the Ui are independent uniform(0, 1) random numbers (see Knuth 1981).
The geometric distribution is often defined on 0, 1, 2, ..., with mean (1 − P)/P. Such deviates can be obtained by subtracting 1 from each element of ir (the returned vector of random deviates).
In this example, imsls_f_random_geometric generates five pseudorandom geometric deviates from a geometric distribution with parameter an equal to 0.3.
#include <stdio.h>
#include <imsls.h>
int main()
{
int n_random = 5;
float p = 0.3;
int *ir;
imsls_random_seed_set(123457);
ir = imsls_f_random_geometric(n_random, p, 0);
imsls_i_write_matrix("Geometric(0.3) random deviates:",
1, n_random, ir, IMSLS_NO_COL_LABELS, 0);
}
Geometric(0.3) random deviates:
1 4 1 2 1