Understanding the Monty Hall problem simulator — concept and principle
This simulator plays the Monty Hall game thousands of times with 3 or more doors and compares the win rates of switching and staying with the theoretical values. You choose how many doors there are and whether the host opens one goat door or all but one. Use it to see, rather than just be told, why switching wins.
How it is calculated
Staying wins only if the first pick was right: P(stay) = 1/n.
Switching, when the host opens all other doors but one: P(switch) = (n − 1)/n.
Switching, when the host opens just one goat door: P(switch) = (n − 1)/n × 1/(n − 2).
- With 3 doors both rules give stay 1/3 and switch 2/3.
- The simulation uses the browser's random generator; change the run number to simulate again.
The principle
The host knows where the prize is and always opens a goat door, so his choice carries information. Your first pick is right only 1 time in 3. In the other 2 times out of 3, the prize is behind one of the other two doors and the host is forced to reveal the goat, leaving the prize behind the remaining door. So switching wins exactly when your first pick was wrong: 2/3 of the time.
Worked example
Default inputs: 3 doors, host opens one goat door, 10,000 games, run 1. The simulation is random, so your numbers will vary slightly; when this page was checked it showed:
- Theoretical: switch wins 66.67 %, stay wins 33.33 %.
- Simulated: switching won 6,725 games, 67.3 %; staying won 3,275 games, 32.8 %.
- Switching wins about 2× as often as staying.
| Run number (change it to simulate again) | Win rate if you switch (simulated) |
|---|---|
| 0.25 | 66.1% |
| 0.5 | 67.1% |
| 0.75 | 66.8% |
| 1 | 66.6% |
| 1.25 | 65.5% |
| 1.5 | 66.7% |
| 2 | 65.4% |
How to read the result
The simulated rates sit within about 1 percentage point of the theory, as expected with 10,000 games. With more doors the advantage grows: with 100 doors and the host opening 98, switching wins 99 % of the time. The puzzle depends on the host's behaviour; if he opened a door at random and happened to show a goat, the odds would be 50/50.
Common mistakes
- Thinking two closed doors must mean 50/50.
- Ignoring that the host knows where the prize is.
- Expecting every small simulation to match the theory exactly.
- Applying the result to a host who might not always offer a switch.
Frequently asked questions
Should you switch in the Monty Hall problem?
Yes, switching wins 2/3 of the time with 3 doors.
Why isn't it 50/50?
The host's choice is not random; it depends on where the prize is.
Who popularised the problem?
Steve Selvin posed it in letters to The American Statistician in 1975.
Sources: S. Selvin (1975), "A problem in probability" and "On the Monty Hall problem", letters, The American Statistician 29(1) and 29(3)