Connect via MCP →

Enter Calculation

Formula

Show calculation steps (1)
  1. Distribution Statistics

    Distribution Statistics: Log-Normal Distribution Random Number Generator

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

Advertisement

Results

Log-Normal Random Numbers Generated
10
positive log-normal variates (Box-Muller)
0.1.700653930
1.0.6142506976
2.0.6849730987
3.0.7422464351
4.1.339691790
5.0.1390862681
6.1.579376176
7.2.106258614
8.0.2934745642
9.0.5611737968
Theoretical mean E[X] = exp(μ + σ²/2) 20.085537
Theoretical median = exp(μ) 2.718282
Theoretical variance Var[X] 21,623.037001

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.

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.

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: