Monte Carlo Simulation for Students: Estimating Pi and Testing Probability Puzzles
How Monte Carlo simulation works, why random points estimate pi, what Buffon's needle shows and how simulations settle the birthday and Monty Hall puzzles.

Monte Carlo Simulation for Students: Estimating Pi and Testing Probability Puzzles
Some probability questions are hard to solve with a formula but easy to act out. Toss the coin, deal the cards, pick the door, and repeat thousands of times. Counting how often something happens gives an estimate of its probability. That idea, called the Monte Carlo method, was named in the 1940s by Stanisław Ulam and John von Neumann after the famous casino. This guide shows how it works with four classic experiments, all of which you can run in the free Monte Carlo simulator.
The basic recipe
- Describe one random trial precisely.
- Decide what counts as a success.
- Repeat the trial N times and count the successes.
- Estimate the probability as successes ÷ N.
The more trials you run, the closer the estimate tends to get to the true value. That last point hides an important detail, which we come back to below.
Estimating pi with random points
Imagine a square dartboard of side 1 with a quarter circle of radius 1 drawn from one corner. Throw darts that land at random anywhere on the square.
- The square has area 1.
- The quarter circle has area π/4.
- So the chance a dart lands inside the quarter circle is π/4.
If 7 853 of 10 000 darts land inside, the estimate is π ≈ 4 × 7853 ÷ 10000 = 3.1412. In the simulator the "Estimate π" experiment does exactly this, colours the first 3 000 points and plots the running estimate as the number of points grows.
Buffon's needle
In 1733 the French naturalist Buffon asked: if you drop a needle on a floor made of parallel boards, how likely is it to cross a gap? For a needle of length l and boards of width t (with l ≤ t), the answer is 2l ÷ (πt). Turn that around and counting crossings estimates π. It is a lovely surprise that π appears in a problem about straight lines, and it was one of the earliest "experiments" in probability. The simulator lets you change the needle length and the gap.
The birthday problem
How many people do you need in a room for a 50 per cent chance that two share a birthday? Most people guess around 180. The real answer is 23.
The exact calculation works with the opposite event, nobody sharing:
P(no match) = 365/365 × 364/365 × … × 343/365 ≈ 0.4927
so P(at least one match) ≈ 0.5073.
The reason it is so high is that with 23 people there are 253 different pairs, and any pair can match. Run the simulation with 23 people and 20 000 groups and you will see about half the groups contain a match.
The Monty Hall problem
A game-show host hides a car behind one of three doors and goats behind the other two. You choose a door. The host, who knows where the car is, opens another door to show a goat and offers you the chance to switch. Should you?
Yes. Switching wins two times in three. If your first choice was a goat (probability 2/3), the host's reveal leaves the car as the only other closed door, so switching wins. If your first choice was the car (1/3), switching loses. The simulator plays the game thousands of times with the switching strategy, and the success rate settles near 0.667. This puzzle famously fooled many mathematicians when it appeared in a magazine column in 1990, which is exactly why simulation is such a useful check.
How accurate is a simulation?
A Monte Carlo estimate has a standard error of about √(p(1 − p) ÷ N), where p is the true probability. The key fact is the square root:
- 100 trials: error around 5 percentage points for p near 0.5.
- 10 000 trials: around 0.5 percentage points.
- 1 000 000 trials: around 0.05 percentage points.
To make the error ten times smaller you need a hundred times more trials. For π with random points, 100 000 points usually give 3.14 correct, and you need around a million to get the third decimal place reliably. The simulator prints a 95 per cent interval with every run so you can see how sure the estimate is.
Why use a seed?
Computers generate "random" numbers from a starting value called a seed. The same seed always gives the same sequence. That makes a simulation repeatable, which matters in science and is handy in class: everyone with seed 42 sees the same result. Change the seed to see how much results vary from run to run.
Ideas for a project
- Plot the error of the π estimate against N on a log scale and check the 1/√N pattern.
- Find the smallest group size for a 90 per cent chance of a shared birthday (it is 41).
- Compare the convergence of the random-points method and Buffon's needle.
Limits
The simulator uses a fast pseudo-random generator that is fine for learning but not for cryptography or research-grade work. The models assume fair dice, well-shuffled cards and birthdays spread evenly through the year, which real data do not quite follow.


