Generates pseudorandom numbers from a lognormal distribution.
#include <imsls.h>
float *imsls_f_random_lognormal (int n_random, float mean, float std, ..., 0)
The type double function is imsls_d_random_lognormal.
int n_random
(Input)
Number of random numbers to generate.
float mean
(Input)
Mean of the underlying normal distribution.
float std
(Input)
Standard deviation of the underlying normal
distribution.
An array of length n_random containing the random deviates of a lognormal distribution. The log of each element of the vector has a normal distribution with mean mean and standard deviation std.
#include <imsls.h>
float
*imsls_f_random_lognormal (int n_random, float
mean,
float std,
IMSLS_RETURN_USER, float r[],
0)
IMSLS_RETURN_USER, float r[]
(Output)
User-supplied array of length n_random containing
the random lognormal deviates.
Function imsls_f_random_lognormal generates pseudorandom numbers from a lognormal distribution with parameters mean and std. The scale parameter in the underlying normal distribution, std, must be positive. The method is to generate normal deviates with mean mean and standard deviation std and then to exponentiate the normal deviates.
With μ = mean and σ = std, the probability density function for the lognormal distribution is
for x > 0. The mean and variance of the lognormal distribution are exp (μ + σ2/2) and exp (2μ + 2σ2) − exp (2μ + σ2), respectively.
In this example, imsls_f_random_lognormal is used to generate five pseudorandom lognormal deviates with a mean of 0 and standard deviation of 1.
#include <stdio.h>
#include <imsls.h>
int main()
{
int n_random = 5;
float mean = 0.0;
float std = 1.0;
float *r;
imsls_random_seed_set(123457);
r = imsls_f_random_lognormal(n_random, mean, std, 0);
imsls_f_write_matrix("lognormal random deviates:",
1, n_random, r, IMSLS_NO_COL_LABELS, 0);
}
lognormal random deviates:
7.780 2.954 1.086 3.588 0.293
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |