IMSL C Stat Library
random_geometric
Generates pseudorandom numbers from a geometric distribution.
Synopsis
#include <imsls.h>
int *imsls_f_random_geometric(int n_random, float p, 0)
The type double function is imsls_d_random_geometric.
Required Arguments
int n_random (Input)
Number of random numbers to generate.
float p (Input)
Probability of success on each trial. Parameter p must be positive and less than 1.0.
Return Value
An integer array of length n_random containing the random geometric deviates.
Synopsis with Optional Arguments
#include <imsls.h>
int *imsls_f_random_geometric (int n_random, float p,
IMSLS_RETURN_USER, int ir[],
0)
Optional Arguments
IMSLS_RETURN_USER, int ir[] (Output)
User-supplied integer array of length n_random containing the random geometric deviates.
Description
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
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).
Example
In this example, imsls_f_random_geometric generates five pseudorandom geometric deviates from a geometric distribution with parameter an equal to 0.3.
 
#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);
}
Output
 
Geometric(0.3) random deviates:
1 4 1 2 1