Generates pseudorandom numbers from a normal, N (μ, σ2), distribution.
#include <imsls.h>
float *imsls_f_random_normal (int n_random, ..., 0)
The type double function is imsls_d_random_normal.
int n_random
(Input)
Number of random numbers to generate.
An array of length n_random containing the random normal deviates.
#include <imsls.h>
float
*imsls_f_random_normal (int n_random,
IMSLS_MEAN, float
mean,
IMSLS_VARIANCE, float
variance,
IMSLS_ACCEPT_REJECT_METHOD,
IMSLS_RETURN_USER, float
r[],
0)
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_ACCEPT_REJECT_METHOD
By
default, random numbers are generated using an inverse CDF technique. When
optional argument IMSLS_ACCEPT_REJECT_METHOD
is specified, an acceptance/ rejection 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.
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, Probablility Distribution Functions and Inverses).
If optional argument IMSLS_ACCEPT_REJECT_METHOD is specified, function imsls_f_random_normal generates pseudorandom numbers using an acceptance/rejection technique due to Kinderman and Ramage (1976). In this method, the normal density is represented as a mixture of densities over which a variety of acceptance/rejection method due to Marsaglia (1964), Marsaglia and Bray (1964), and Marsaglia et al. (1964) are applied. This method is faster than the inverse CDF technique.
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.
In this example, imsls_f_random_normal generates five pseudorandom deviates from a standard normal distribution.
#include <imsls.h>
#define N_RANDOM 5
void 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]);
}
Standard normal random deviates:
1.8279 -0.6412 0.7266 0.1747 1.0145
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |