Chapter 10: Statistics and Random Number Generation

.p>.CMCH10.DOC!RANDOM_NORMAL;random_normal

Generates pseudorandom numbers from a standard normal distribution using an inverse CDF method.

Synopsis

#include <imsl.h>

float *imsl_f_random_normal (int n_random, ¼, 0)

The type double function is imsl_d_random_normal.

Required Arguments

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

Return Value

A pointer to a vector of length n_random containing the random standard normal deviates. To release this space, use free.

Synopsis with Optional Arguments

#include <imsl.h>

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

Optional Arguments

IMSL_RETURN_USER, float r[]   (Output)
Pointer to a vector of length n_random that will contain the generated random standard normal deviates.

Description

Function imsl_f_random_normal generates pseudorandom numbers from a standard normal (Gaussian) distribution using an inverse CDF technique. In this method, a uniform (0, 1) random deviate is generated. Then, the inverse of the normal distribution function is evaluated at that point, using the function imsl_f_normal_inverse_cdf (See Chapter 11 of the IMSL C Stat Numerical  Library.)

Deviates from the normal distribution with mean mean and standard deviation std_dev can be obtained by scaling the output from imsl_f_random_normal. The following statements (in single precision) would yield random deviates from a normal (mean, std_dev2) distribution.

   float *r;
   r = imsl_f_random_normal (n_random, 0);
   for (i=0; i<n_random; i++) 
      r[i] = r[i]*std_dev + mean;

Example

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

#include <imsl.h>

#define N_RANDOM        5

void main()
{
    int         seed = 123457;
    int         n_random = N_RANDOM;
    float       *r;

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

Output

Standard normal random deviates:   1.8279 -0.6412  0.7266  0.1747  1.0145

Remark

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.


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