Chapter 12: Random Number Generation

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 succes 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 distribu­tion 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)x1

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 <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);

}

Output

Geometric(0.3) random deviates:

       1   4   1   2   1


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260