random.lognormvariate(mu, sigma)
The random.lognormvariate function returns a random number drawn from a log-normal distribution.
- mu: Mean of the distribution.
- sigma: Standard deviation of the distribution.
The random.lognormvariate function returns a real number.
We can generate a random number extracted from a log-normal distribution with mean 5 and standard deviation 3 with the following code:
To confirm the distribution from which the random numbers are extracted, we can generate one hundred thousand random numbers from a log-normal distribution with mean 5 and standard deviation 3, obtain their natural logarithm and show their histogram:
import math
plt.hist([math.log(random.lognormvariate(5, 3)) for i in range(100000)], bins = 100)
plt.grid()
plt.show()
We can see that it is indeed a normal distribution.