How to generate random numbers from a log-normal distribution in Python ? Last Updated : 07 Apr, 2021 Comments Improve Suggest changes Like Article Like Report A continuous probability distribution of a random variable whose logarithm is usually distributed is known as a log-normal (or lognormal) distribution in probability theory. A variable x is said to follow a log-normal distribution if and only if the log(x) follows a normal distribution. The PDF is defined as follows. Probability Density function Log-normal Where mu is the population mean & sigma is the standard deviation of the log-normal distribution of a variable. Just like normal distribution which is a manifestation of summation of a large number of Independent and identically distributed random variables, lognormal is the result of multiplying a large number of Independent and identically distributed random variables. Generating a random number from a log-normal distribution is very easy with help of the NumPy library. Syntax: numpy.random.lognormal(mean=0.0, sigma=1.0, size=None) Parameter: mean: It takes the mean value for the underlying normal distribution.sigma: It takes only non-negative values for the standard deviation for the underlying normal distributionsize : It takes either a int or a tuple of given shape. If a single value is passed it returns a single integer as result. If a tuple then it returns a 2D matrix of values from log-normal distribution. Returns: Drawn samples from the parameterized log-normal distribution(nd Array or a scalar). The below example depicts how to generate random numbers from a log-normal distribution: Python3 # import modules import numpy as np import matplotlib.pyplot as plt # mean and standard deviation mu, sigma = 3., 1. s = np.random.lognormal(mu, sigma, 10000) # depict illustration count, bins, ignored = plt.hist(s, 30, density=True, color='green') x = np.linspace(min(bins), max(bins), 10000) pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) / (x * sigma * np.sqrt(2 * np.pi))) # assign other attributes plt.plot(x, pdf, color='black') plt.grid() plt.show() Output: Let's prove that log-Normal is a product of independent and identical distributions of a random variable using python. In the program below we are generating 1000 points randomly from a normal distribution and then taking the product of them and finally plotting it to get a log-normal distribution. Python3 # Importing required modules import numpy as np import matplotlib.pyplot as plt b = [] # Generating 1000 points from normal distribution. for i in range(1000): a = 12. + np.random.standard_normal(100) b.append(np.product(a)) # Making all negative values into positives b = np.array(b) / np.min(b) count, bins, ignored = plt.hist(b, 100, density=True, color='green') sigma = np.std(np.log(b)) mu = np.mean(np.log(b)) # Plotting the graph. x = np.linspace(min(bins), max(bins), 10000) pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) / (x * sigma * np.sqrt(2 * np.pi))) plt.plot(x, pdf,color='black') plt.grid() plt.show() Output: Comment More infoAdvertise with us Next Article How to generate random numbers from a log-normal distribution in Python ? A arun singh Follow Improve Article Tags : Python Python-numpy Practice Tags : python Similar Reads How to Generate Random Numbers from Standard Distributions in R Standard Distributions, We have heard this term when working with statistics and data analysis. It is essential to have a technique, for generating numbers that adhere to probability distributions. This allows us to simulate data accurately for tasks like hypothesis testing and Monte Carlo simulatio 6 min read Generate five random numbers from the normal distribution using NumPy In Numpy we are provided with the module called random module that allows us to work with random numbers. The random module provides different methods for data distribution. In this article, we have to create an array of specified shape and fill it random numbers or values such that these values are 2 min read How to generate a random number between 0 and 1 in Python ? The use of randomness is an important part of the configuration and evaluation of modern algorithms. Here, we will see the various approaches for generating random numbers between 0 ans 1. Method 1: Here, we will use uniform() method which returns the random number between the two specified numbers 1 min read How to Plot a Log Normal Distribution in R In this article, we will explore how to plot a log-normal distribution in R, providing you with an understanding of its properties and the practical steps for visualizing it using R Programming Language.Log-Normal DistributionThe log-normal distribution is a probability distribution of a random vari 5 min read Generate Random Numbers From The Uniform Distribution using NumPy Random numbers are the numbers that cannot be predicted logically and in Numpy we are provided with the module called random module that allows us to work with random numbers. To generate random numbers from the Uniform distribution we will use random.uniform() method of random module. Syntax: nump 1 min read How to plot a normal distribution with Matplotlib in Python? Normal distribution, also known as the Gaussian distribution, is a fundamental concept in probability theory and statistics. It is a symmetric, bell-shaped curve that describes how data values are distributed around the mean. The probability density function (PDF) of a normal distribution is given b 4 min read How to Create a Normal Distribution in Python PyTorch In this article, we will discuss how to create Normal Distribution in Pytorch in Python. torch.normal() torch.normal() method is used to create a tensor of random numbers. It will take two input parameters. the first parameter is the mean value and the second parameter is the standard deviation (std 2 min read Python - Power Log-Normal Distribution in Statistics scipy.stats.powerlognorm() is a power log-normal continuous random variable. It is inherited from the of generic methods as an instance of the rv_continuous class. It completes the methods with details specific for this particular distribution. Parameters : q : lower and upper tail probability x : q 2 min read How to Generate Random Numbers in R Random number generation is a process of creating a sequence of numbers that don't follow any predictable pattern. They are widely used in simulations, cryptography and statistical modeling. R Programming Language contains various functions to generate random numbers from different distributions lik 2 min read Python - Log Normal Distribution in Statistics scipy.stats.lognorm() is a log-Normal continuous random variable. It is inherited from the of generic methods as an instance of the rv_continuous class. It completes the methods with details specific for this particular distribution. Parameters : q : lower and upper tail probability x : quantiles lo 2 min read Like