1,000
2

More information about the Monte Carlo method

Monte Carlo π

Can pure chance compute an exact number? Draw a circle inside a square and throw darts at it at random. The circle covers π/4 of the square, so about π/4 of the darts land inside it. Multiply that share by four and you have an estimate of π. The more darts, the closer it gets: 3, then 3.1, then 3.14, then 3.141… Press Start and darts land at random in the square. The share that lands inside the circle is π/4, so π ≈ 4 × inside ÷ darts. The more darts, the closer the estimate: a hundred times as many darts buy about one more correct digit. Click the square to throw a dart by hand.

How it works

  1. Press Start. Darts land at random in the square: blue inside the circle, red outside it.
  2. Watch the counter: π ≈ 4 × inside ÷ darts. The digits that already match π are coloured.
  3. Turn up the speed or throw a million darts at once, and see the estimate settle inside the narrowing band on the chart.

Why the darts find π

The square has sides of length 2 and the circle inside it has radius 1. The square's area is 4 and the circle's is π × 1² = π. A dart that is equally likely to land anywhere in the square lands inside the circle with probability π/4, about 78.5%. Count the darts, count the hits, and 4 × hits ÷ darts estimates π. The quarter circle works the same way: a quarter of a circle of radius 1 in a square of side 1 also covers π/4 of it.

The law of large numbers

One dart tells you nothing: it gives 4 or 0. A hundred darts give something like 3.0 or 3.3. Ten thousand darts usually land within a few hundredths of π. The law of large numbers says that the share of hits gets ever closer to π/4 as the number of darts grows, so the estimate converges to π.

Why it converges slowly

The typical error after N darts is about 1.64/√N. To halve the error you need four times as many darts, and one more correct digit costs a hundred times as many. The shaded band on the chart holds 95% of all runs and narrows like 1/√N. A million darts leave an error of about 0.0016: three or four correct decimals.

Monte Carlo methods

The method is named after the casino in Monaco. In the 1940s Stanislaw Ulam and John von Neumann used random sampling to follow neutrons through matter, a problem too tangled for formulas. Today Monte Carlo simulations price financial options, render the light in animated films, forecast the weather and test medicines. Throwing darts at a circle is the simplest example of the idea: replace a hard calculation by many random experiments.

Frequently asked questions

How do random darts calculate π?

The circle covers π/4 of the square around it. When darts land uniformly at random, about π/4 of them hit the circle, so four times the share of hits is an estimate of π.

How many darts do I need for 3.14?

Usually tens of thousands. The error shrinks like 1.64/√N: 10,000 darts are typically about 0.016 off and 1,000,000 darts about 0.0016. Each extra correct digit costs a hundred times as many darts.

Is this the same as Buffon's Needle?

Both estimate π with chance. Buffon's Needle drops needles on lines and counts the crossings; the Monte Carlo method throws points at a circle. The darts are easier to understand and converge faster: for the same number of throws the error is about a third of that of Buffon's half-needle experiment.

Are the darts really random?

They come from your browser's pseudo-random number generator, which is more than good enough for this experiment. Every run is different, which is why the estimate wanders before it settles.

Does this upload anything?

No. Everything is calculated and drawn on a canvas in your browser. Save downloads a PNG. Edit opens that image in the PictorX editor.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor