random_lognormal


   more...

Generates pseudorandom numbers from a lognormal distribution.

Synopsis

#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.

Required Arguments

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.

Return Value

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.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_random_lognormal (int n_random, float mean, float std,
IMSLS_RETURN_USER, float r[],
0)

Optional Arguments

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

Description

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 exp ( + σ2), respectively.

Example

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 <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);

}

Output

 

lognormal random deviates:

7.780 2.954 1.086 3.588 0.293