Log-Normal Distribution Random Number Generator

Log-Normal Distribution Random Number Generator

Emerging AI Skill PRO

Enter Calculation

Formula

X=exp⁡(μ+σZ)where{Z=−2ln⁡U1cos⁡(2πU2)U1,U2∼Uniform(0,1)\begin{gathered} X = \exp\!\left({\mu} + {\sigma}\, Z\right) \\[1.5em] \text{where}\quad \left\{ \begin{aligned} Z &= \sqrt{-2\ln U_1}\,\cos(2\pi U_2) \\ U_1, U_2 &\sim \text{Uniform}(0,1) \end{aligned} \right. \end{gathered}
Show calculation steps (1)
  1. Distribution Statistics

    Mean=exp⁡(μ+12σ2)Median=exp⁡(μ)Var=(eσ2−1)e2μ+σ2\begin{aligned} \text{Mean} &= \exp\!\left({\mu} + \tfrac{1}{2}{\sigma}^{2}\right) \\ \text{Median} &= \exp\!\left({\mu}\right) \\ \text{Var} &= \left(e^{{\sigma}^{2}} - 1\right) e^{\,2{\mu} + {\sigma}^{2}} \end{aligned}

    Theoretical mean, median, and variance of the log-normal distribution from mu and sigma.

Usage stats

Advertisement

Results

Log-Normal Random Numbers Generated
10
positive log-normal variates (Box-Muller)
0.48.50416703
1.19.01293786
2.2.195688557
3.0.5246943613
4.15.87817281
5.0.2066790160
6.0.1913328283
7.4.554890384
8.3.897796890
9.5.998097561
Theoretical mean 20.085537
Theoretical median 2.718282
Theoretical variance Var[X] 21,623.037001

Report an error on this page

What this generator does

This tool produces a list of pseudo-random numbers that follow a log-normal distribution. A random variable X is log-normal when its natural logarithm, \(\ln(X)\), is normally distributed. The generator first creates standard-normal variates with the classic Box-Muller transform, scales them to the target normal \(N(\mu, \sigma^2)\), and then exponentiates to obtain strictly positive log-normal values.

Skewed log-normal probability density curve with marked mean, median and mode
The log-normal distribution is positive-valued and right-skewed, with mode < median < mean.

Important: what mu and sigma mean

The parameters \(\mu\) and \(\sigma\) describe the underlying normal distribution of \(\ln(X)\) — they are not the mean and standard deviation of X itself. The actual mean of X is \(\exp(\mu + \sigma^2/2)\), the median is \(\exp(\mu)\), and the variance is \((\exp(\sigma^2) - 1)\cdot\exp(2\mu + \sigma^2)\). These reference values are shown alongside your sample so you can sanity-check the output.

$$\begin{aligned} \text{Mean} &= \exp\!\left(\mu + \tfrac{1}{2}\sigma^{2}\right) \\ \text{Median} &= \exp\!\left(\mu\right) \\ \text{Var} &= \left(e^{\sigma^{2}} - 1\right) e^{\,2\mu + \sigma^{2}} \end{aligned}$$

How to use it

Enter \(\mu\) (any real number), \(\sigma\) (zero or positive), and how many numbers you want (1 to 1000). Pick how many significant digits to display. Each run draws fresh uniform random numbers, so the values change every time. Because the Box-Muller method yields two normal variates per uniform pair, an odd count simply discards one spare variate.

Advertisement

The formula explained

For uniforms \(U_1, U_2\) in \((0,1]\):

$$X = \exp\!\left(\mu + \sigma\, Z\right), \quad Z = \sqrt{-2\ln U_1}\,\cos(2\pi U_2)$$

\(Z = \sqrt{-2\cdot\ln U_1}\cdot\cos(2\pi\cdot U_2)\) gives \(Z \sim N(0,1)\). Then \(Y = \mu + \sigma\cdot Z\) is \(N(\mu, \sigma^2)\), and \(X = \exp(Y)\) is log-normal. We guard against \(\ln(0)\) by clamping \(U_1\) to a tiny epsilon.

$$\begin{gathered} X = \exp\!\left(\mu + \sigma\, Z\right) \\[1.5em] \text{where}\quad \left\{ \begin{aligned} Z &= \sqrt{-2\ln U_1}\,\cos(2\pi U_2) \\ U_1, U_2 &\sim \text{Uniform}(0,1) \end{aligned} \right. \end{gathered}$$
Flow diagram of Box-Muller transform converting two uniform numbers into a log-normal value
Two uniform randoms become a standard normal Z via Box-Muller, then are scaled and exponentiated into X.

Worked example

With \(\mu = 1\), \(\sigma = 2\), take \(U_1 = 0.5\), \(U_2 = 0.25\). Then \(R = \sqrt{-2\cdot\ln 0.5} = 1.17741\). \(Z_1 = R\cdot\cos(\pi/2) = 0\) and \(Z_2 = R\cdot\sin(\pi/2) = 1.17741\). So

$$X_1 = \exp(1) = 2.71828$$

and

$$X_2 = \exp(1 + 2\cdot 1.17741) = \exp(3.35482) \approx 28.64$$

The theoretical mean \(\exp(3) = 20.0855\) and median \(\exp(1) = 2.71828\) are consistent.

How Mu and Sigma Change the Distribution

The parameters \(\mu\) and \(\sigma\) are the mean and standard deviation of \(\ln X\), not of \(X\) itself. The theoretical values the calculator reports follow these formulas:

  • Median: \(e^{\mu}\)
  • Mean: \(e^{\mu+\sigma^2/2}\)
  • Variance: \((e^{\sigma^2}-1)\,e^{2\mu+\sigma^2}\)
\(\mu\) \(\sigma\) Median \(e^{\mu}\) Mean Variance Mean/median \(e^{\sigma^2/2}\)
0 0.25 1.0000 1.0317 0.0687 1.0317
0 0.5 1.0000 1.1331 0.3647 1.1331
0 1 1.0000 1.6487 4.6708 1.6487
1 0.5 2.7183 3.0802 2.6948 1.1331
1 2 2.7183 20.0855 21,623.04 7.3891

Worked check for (1, 2): the mean is \(e^{1+4/2}=e^{3}\approx 20.0855\). The variance is \((e^{4}-1)\,e^{2+4}=e^{10}-e^{6}\approx 22026.47-403.43=21623.04\).

Note on the ratio: mean divided by median is always \(e^{\sigma^2/2}\), so it depends only on \(\sigma\). Changing \(\mu\) rescales the whole distribution (the median is multiplied by \(e^{\Delta\mu}\)) without changing its shape. Increasing \(\sigma\) makes the right tail heavier, and the mean pulls far above the median.

Advertisement

Key Terms

Log-normal distribution
The distribution of a positive variable \(X\) whose natural logarithm \(\ln X\) is normally distributed.
Mu (\(\mu\))
The mean of \(\ln X\). It sets the scale: the median of \(X\) is \(e^{\mu}\).
Sigma (\(\sigma\))
The standard deviation of \(\ln X\). It must be positive and controls the spread and skew.
Standard normal Z
A normal variate with mean 0 and variance 1. Here \(X=e^{\mu+\sigma Z}\).
Uniform variate U
A random number evenly distributed between 0 and 1. Box-Muller uses two of them, \(U_1\) and \(U_2\), and \(U_1\) must be greater than 0.
Box-Muller transform
A method that turns two independent uniform variates into standard normal ones, for example \(Z=\sqrt{-2\ln U_1}\cos(2\pi U_2)\).
Pseudo-random number
A number produced by a deterministic algorithm that behaves statistically like a random one, but is not truly random.
Mean, median, mode
The average, the middle value, and the most frequent value (the peak of the density). For the log-normal: mean \(e^{\mu+\sigma^2/2}\), median \(e^{\mu}\), mode \(e^{\mu-\sigma^2}\). Mode < median < mean.
Variance
The average squared deviation from the mean. For the log-normal it is \((e^{\sigma^2}-1)e^{2\mu+\sigma^2}\).
Right skew
An asymmetry with a long tail toward large values, which pulls the mean above the median.

FAQ

Why are my values different each run? It is a stochastic generator using Math.random(); without a fixed seed each run differs.

What if sigma = 0? The distribution is degenerate and every value equals \(\exp(\mu)\).

Can a value be negative? No — log-normal support is \((0, \infty)\), so all outputs are strictly positive.

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators