Monte Carlo: finding π by throwing random darts
In weather forecasts, game AI, movie lighting and nuclear-physics simulations, which all answer hard questions with lots of random tries
What problem does it solve?
Can you calculate π using nothing but random numbers?
The big idea
Draw a quarter circle of radius 1 inside a 1×1 square. Its area is π/4, so a random dart landing in the square hits the quarter circle with probability exactly π/4. Throw enough darts, count the hits, and π falls out of pure chance. The deep idea: when a problem is too complicated to solve exactly, simulate it randomly many times and let averages do the work.
How it works, step by step
- 1. Pick two random numbers x and y between 0 and 1: that's a dart in the square.
- 2. If x² + y² ≤ 1, the dart is inside the quarter circle.
- 3. Repeat thousands of times, counting hits.
- 4. Estimate π ≈ 4 × hits ÷ total darts.
The key formula
- the total number of random darts
- darts with x² + y² ≤ 1, inside the quarter circle
- because the quarter circle covers π/4 of the square
How fast is it?
Slow but simple: the typical error shrinks like 1/√N, so each extra correct digit needs about 100 times more darts. Its superpower is that the same trick works in 100 dimensions, where exact methods drown.
Try it yourself
- Run it with 100 darts five times. How much do the answers differ?
- Change the test to estimate the area under y = x² from 0 to 1. The exact answer is 1/3.
Fun fact
The name comes from the Monte Carlo casino in Monaco. Stanisław Ulam got the idea in 1946 while estimating his chances of winning a game of solitaire, and used it with John von Neumann to simulate neutrons for nuclear physics.