Chapter 10: Statistics and Random Number Generation

.p>.CMCH10.DOC!RANDOM_EXPONENTIAL;random_exponential

Generates pseudorandom numbers from a standard exponential distribution.

Synopsis

#include <imsl.h>

float *imsl_f_random_exponential (int n_random, ¼, 0)

The type double function is imsl_d_random_exponential.

Required Arguments

int n_random   (Input)
Number of random numbers to generate.

Return Value

A pointer to an array of length n_random containing the random standard exponential deviates.

Synopsis with Optional Arguments

#include <imsl.h>

float *imsl_f_random_exponential (int n_random,
IMSL_RETURN_USER, float r[],
0)

Optional Arguments

IMSL_RETURN_USER, float r[]   (Output)
If specified, the array of length n_random containing the random standard exponential deviates is returned in the user-provided array r.

Description

Function imsl_f_random_exponential generates pseudorandom numbers from a standard exponential distribution. The probability density function is f(x) = e-x, for x > 0. Function imsl_random_exponential uses an antithetic inverse CDF technique; that is, a uniform random deviate U is generated, and the inverse of the exponential cumulative distribution function is evaluated at 1.0  U to yield the exponential deviate.

Deviates from the exponential distribution with mean θ can be generated by using imsl_f_random_exponential and then multiplying each entry in r by θ.

Example

In this example, imsl_f_random_exponential is used to generate five pseudorandom deviates from a standard exponential distribution.

#include <imsl.h>

#define N_RANDOM    5

main()

{
    int             seed = 123457;
    int             n_random = N_RANDOM;
    float           *r;

    imsl_random_seed_set(seed);
    r = imsl_f_random_exponential(n_random, 0);
    printf("%s: %8.4f%8.4f%8.4f%8.4f%8.4f\n",
           "Exponential random deviates",
           r[0], r[1], r[2], r[3], r[4]);
}

Output

Exponential random deviates:   0.0344  1.3443  0.2662  0.5633  0.1686


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