The Monte Carlo method and π
The Monte Carlo method answers questions with random experiments instead of formulas. Its classic first example estimates π by throwing darts at a circle inside a square.
Areas as probabilities
Pick a point at random in a square, every spot equally likely. The chance that it lands in some region is the area of the region divided by the area of the square. A circle of radius 1 has area π, and the square around it has sides of 2 and area 4. So a random point lands inside the circle with probability P = π/4 ≈ 0.785.
From hits to π
Throw N darts and count the hits H inside the circle. The share H/N estimates π/4, so
π ≈ 4H / N
The test for a hit needs no π at all: a point (x, y), measured from the centre with the radius as the unit, is inside the circle when x² + y² ≤ 1. The π comes out of the counting.
The quarter-circle version puts the centre in one corner of a square of side 1. The quarter circle covers π/4 of that square too, so the same formula holds.
The law of large numbers
Each dart is a small experiment with two outcomes: a hit, with probability p = π/4, or a miss. The law of large numbers, proved by Jacob Bernoulli and published in 1713, says that the share of hits gets arbitrarily close to p as N grows. It does not say that hits and misses balance out in the short run: the estimate can wander away from π for a long time before it comes back.
How fast is it?
The number of hits follows a binomial distribution. Its standard deviation, turned into units of π, gives the typical error
σ ≈ 4 · √(p(1 − p) / N) ≈ 1.64 / √N
After 100 darts that is about 0.16, after 10,000 about 0.016, after a million about 0.0016. The error shrinks with the square root of N: a hundred times as many darts buy one more correct digit. In the app the shaded band is ±1.96σ, which holds 95% of all runs, and the ± after the estimate is one standard error.
Where the name comes from
In 1946 Stanislaw Ulam, recovering from an illness, wondered how likely it was to win a game of solitaire. Instead of counting all possible deals, he thought of simply playing many games and counting the wins. With John von Neumann he turned the idea into a method for the neutron calculations at Los Alamos, and their colleague Nicholas Metropolis named it after the Monte Carlo casino, where Ulam's uncle liked to gamble. Much older experiments with chance, such as Buffon's Needle from 1777, already estimated π in the same spirit.
Explore it in PictorX
Open Monte Carlo π and the darts are already flying, a thousand a second. The counter colours the digits that already agree with π, and the chart shows the estimate on a logarithmic axis inside the band where 95% of runs end up. Slow motion throws one dart a second and draws its distance to the centre; click the square to throw a dart yourself. A million darts throws them all at once. Quarter circle switches to the corner version, and Fade old darts keeps the picture lively at high speed. Save a PNG, or compare with Buffon's Needle, which estimates π with falling needles.
Frequently asked questions
Who invented the Monte Carlo method?
Stanislaw Ulam and John von Neumann developed it in the late 1940s at Los Alamos, and Nicholas Metropolis gave it its name. Random experiments that estimate numbers are older, for example Buffon's Needle from 1777.
Why is the probability π/4?
A circle of radius 1 has area π, and the square around it has area 4. A point that is equally likely to land anywhere in the square lands in the circle with probability π/4.
How accurate is the estimate?
One standard error is about 1.64/√N for N darts. A thousand darts are typically about 0.05 off, a million darts about 0.0016.
Is the Monte Carlo method a good way to compute π?
No. Formulas have computed trillions of digits of π; random darts struggle to get six. The method shines where no formula exists, such as the paths of neutrons, the risk of an investment or light bouncing through a scene.
Does the estimate ever reach exactly π?
No. After N darts the estimate is a fraction 4H/N, and π is irrational, so it can never be exact. It only gets closer, with ever higher probability.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Try Monte Carlo π