random_normal


   more...

Generates pseudorandom numbers from a normal, N (μσ2), distribution.

Synopsis

#include <imsls.h>

float *imsls_f_random_normal(int n_random, 0)

The type double function is imsls_d_random_normal.

Required Arguments

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

Return Value

An array of length n_random containing the random normal deviates.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_random_normal (int n_random,
IMSLS_MEAN
, float mean,
IMSLS_VARIANCE, float variance,
IMSLS_ZIGGURAT_METHOD
,
IMSLS_RETURN_USER
, float r[],
0)

Optional Arguments

IMSLS_MEAN, float mean (Input)
Parameter mean contains the mean, μ, of the N(μσ2) from which random normal deviates are to be generated.

Default: mean = 0.0

IMSLS_VARIANCE, float variance (Input)
Parameter variance contains the variance of the N (μσ2) from which random normal deviates are to be generated.

Default: variance = 1.0

IMSLS_ZIGGURAT_METHOD, (Input)
By default, random numbers are generated using an inverse CDF technique. When optional argument IMSLS_ZIGGURAT_METHOD is specified, the Ziggurat method is used instead. See the “Description” section for details about each method.

IMSLS_RETURN_USER, float r[] (Output)
User-supplied array of length n_random containing the generated random standard normal deviates.

Description

By default, function imsls_f_random_normal generates pseudorandom numbers from a normal (Gaussian) distribution using an inverse CDF technique. In this method, a uniform (0, 1) random deviate is generated. The inverse of the normal distribution function is then evaluated at that point, using the function imsls_f_normal_inverse_cdf (Chapter 11, Probability Distribution Functions and Inverses).

If optional argument IMSLS_ZIGGURAT_METHOD is specified, function imsls_f_random_normal generates pseudorandom numbers using the Ziggurat method. This method cuts the density into many small pieces. For each random number generated, an interval is chosen at random and a random normal is generated from the chosen interval. In this implementation, the density is cut into 256 pieces, but symmetry is used so that only 128 pieces are needed by the computation. Following Doornik (2005), different uniform random deviates are used to determine which slice to use and to determine the normal deviate from the slice. This method is faster than the default inverse CDF technique.

Remarks

Function imsls_random_seed_set can be used to initialize the seed of the random number generator; function imsls_random_option can be used to select the form of the generator.

Example

In this example, imsls_f_random_normal generates five pseudorandom deviates from a standard normal distribution.

 

#include <imsls.h>

#include <stdio.h>

#define N_RANDOM 5

 

int main()

{

int seed = 123457;

int n_random = N_RANDOM;

float *r;

 

imsls_random_seed_set (seed);

r = imsls_f_random_normal(n_random, 0);

printf("%s:\n%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:

 

-0.6412 0.7266 0.1747 1.0145