randomLognormal

../../_images/OpenMp_27.png

Generates pseudorandom numbers from a lognormal distribution.

Synopsis

randomLognormal (nRandom, mean, std)

Required Arguments

int nRandom (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 nRandom 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.

Description

Function randomLognormal 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

\[f(x) = \frac{1}{\sigma x \sqrt{2\pi}} \exp \left[-\frac{1}{2\sigma^2}(\ln x - \mu)^2\right]\]

for \(x>0\). The mean and variance of the lognormal distribution are \(\exp(\mu+\sigma^2/2)\) and \(\exp(2\mu+2\sigma^2)-\exp(2\mu+\sigma^2)\), respectively.

Example

In this example, randomLognormal is used to generate five pseudorandom lognormal deviates with a mean of 0 and standard deviation of 1.

from numpy import *
from pyimsl.stat.randomLognormal import randomLognormal
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix

n_random = 5
mean = 0.0
std = 1.0
randomSeedSet(123457)
r = randomLognormal(n_random, mean, std)
writeMatrix("Lognormal random deviates", r, noColLabels=True)

Output

 
                   Lognormal random deviates
      7.780        2.954        1.086        3.588        0.293