Central Limit Theorem Simulator

Most CLT demos show you a bell curve appearing and stop there. This one measures how far from normal the sample means still are, so you can see for yourself that “n = 30 is enough” is a property of the population, not a law.

30

Left (on wider screens): the population itself. Right: the distribution of the mean of n draws, standardised, with the normal curve on top. The Kolmogorov–Smirnov (KS) distance is the largest gap between the two cumulative curves; switch the view to CDF to see exactly where it is.

KS distance to N(0, 1)—
Skewness of the means · γ/√n—
Beyond 3σ · normal 0.27%—
n for KS < 0.01 · rule 100 γ²—

Press “Sweep n” to plot the KS distance for the selected population at n = 1, 2, 3, 5, 10, 20, 30, 50, 100, 200, 500, 1000 (20,000 means each). Curves for different populations accumulate so you can compare them. The dashed line is 0.01, the practical “indistinguishable” level; the dotted line is the 5% critical value for this test, about 0.0066 — below it, the 20,000 means cannot be told from normal at all.

What is on the screen

Pick a population, pick a sample size n, and the tool draws n values, averages them, and repeats that 20,000 times (2,000 or 100,000 if you prefer). The 20,000 means are standardised by their own mean and standard deviation, so what is left is pure shape, and that shape is drawn as a histogram with the standard normal density on top. The central limit theorem says the shape tends to the bell as n grows. It does not say how fast, and it does not say the tails get there at the same time as the middle. That is what the numbers underneath are for.

Why “n = 30” is not a law

The experiment this tool grew out of ran seven populations through exactly this procedure with 20,000 means at each of twelve sample sizes. At n = 30 the KS distances were: uniform 0.004, exponential 0.027, chi-square (df = 1) 0.034, log-normal 0.061, coin flip 0.073, Cauchy 0.081, rare event with p = 0.01 0.449. The uniform case is already at the noise floor. The rare-event case is nowhere near a bell: with p = 0.01 and n = 30, three quarters of all samples contain no event at all, so the “distribution of the mean” is a spike at zero with a few bumps to its right.

Asking the other way round — what is the smallest n at which KS drops below 0.01? — gives uniform 5, exponential 1000, chi-square 1000, and for the log-normal, the rare event, the coin and the Cauchy: not within the tested range of n ≤ 1000. The pattern behind these numbers is that the leading correction to the bell shape scales as γ/√n, so pushing the KS distance under a fixed threshold needs n proportional to γ². The write-up condensed that into a rule of thumb, n ≳ 100 γ²: about 400 for the exponential (γ = 2), 800 for the chi-square (γ = 2.83), nearly 4,000 for the log-normal (γ = 6.18) and almost 10,000 for the rare event (γ = 9.85). The last readout above shows this figure for whatever population is selected.

The tails converge last

At n = 30 the shares of means beyond 3σ were: uniform 0.27% (exactly normal), exponential 0.44%, chi-square 0.60%, log-normal 1.10% — 4.1 times the normal value — and Cauchy 14.03%, 52 times. Select the log-normal preset and look at the right-hand edge of the histogram: the middle looks fine, the bump on the right is where the extra 3σ events live. If you build a 99.7% interval from those means assuming normality, it will fail four times as often as advertised. That is the practical content of the theorem being “not yet true”.

Two ways the theorem does not apply

Lattice populations. The mean of n coin flips can only take n + 1 values, so its CDF is a staircase, and the largest gap between a staircase and a smooth curve is at least half a step. That puts a floor under the KS distance of roughly 0.4/√n — 0.073 at n = 30, 0.013 at n = 1000 — even though the outline of the histogram is a perfect bell from n ≈ 20 on. The experiment measured 0.073 and 0.017 at those two sizes: the floor, plus sampling noise once the floor gets as small as the noise. Convergence “in distribution” is happening; the KS statistic just refuses to say so. The die behaves the same way with a finer lattice. Run the sweep for the coin and you will see its curve follow the 0.4/√n reference line all the way down.

The Cauchy distribution. It has no mean and no variance, so the theorem’s hypothesis fails and the mean of n Cauchy draws is itself Cauchy, whatever n is. The KS distance in the experiment sat at 0.083 for every n from 1 to 1000. Because the sample standard deviation of Cauchy means is meaningless — one draw in a thousand dominates it — the tool standardises this population by the median and the interquartile range divided by 1.349, exactly as the experiment did; otherwise the “z” axis would collapse and the histogram would be a single bar. Select it, drag n from 1 to 1000, and watch nothing change.

Reading it honestly

What will you try next?

Share this tool

Part of Shake AI Lab — interactive experiments in mathematics and machine learning. · More tools · 日本語の解説記事