The Monty Hall problem

One door hides a car and the other two hide goats. You pick a door. The host, who knows where the car is, opens a different door to show a goat, then lets you stay with your pick or switch to the last closed door.

Pick a door.

Keys: 1 2 3 choose a door, N starts a new game.

Your games
ChoicePlayedWonWin rate
Stayed00–
Switched00–

Simulate many games

Both choices are played on the same games, so in every game exactly one of them wins.

Doors
Play

Switching won – No games yet

Staying won – No games yet

Why switching wins

Your first pick is the car one time in three. The host knows where the car is and can always open a goat door, so opening one tells you nothing new about your own door. It still wins one time in three, which leaves two in three for the door he kept shut.

Put another way, switching loses only when your first pick was the car. That happens 1/3 of the time, so switching wins 2/3 of the time.

More doors make it easier to feel. With 100 doors, you pick one and the host opens 98 goat doors, leaving one other door closed. Switching wins unless your first guess was right: 99 times in 100.

These numbers depend on the host's rules. He always opens a door you did not pick, always reveals a goat, and always offers the switch. A host who offered a switch only when your first pick was the car would make switching lose every time.

The birthday problem

How many people does a room need before two of them probably share a birthday?

50.7%

chance that at least two people share a birthday

Pairs of people
253
Chance someone shares your birthday
5.9%

Fill rooms at random

Counting the ways to miss

It is easier to work out the chance that everyone has a different birthday. The second person misses the first person's birthday with probability 364/365, the third misses both with probability 363/365, and so on down the line. Multiply those together and subtract from 1.

The surprise comes from pairs. Twenty-three people make 253 pairs, and every pair is a chance for a match. A match with one particular birthday, such as yours, is much rarer: it takes 253 other people before that chance passes 50%.

The model assumes 365 equally likely birthdays and leaves out February 29. Real birthdays are not spread perfectly evenly, and any unevenness makes a match slightly more likely.

The Galton board

Balls fall through rows of pins. At every pin a ball bounces left or right, and the bins at the bottom collect where it lands.

Balls landed 0

Average right bounces –

Expected value 6.00

Counts by bin
Right bouncesBallsShareExact probability

Pascal's triangle in the pins

To land in bin k of a board with n rows, a ball has to bounce right exactly k times out of n. The number of paths that do that is the binomial coefficient, entry k of row n in Pascal's triangle. On a fair board every path has probability 1/2n, and in general:

P(bin k) = n!k! (n − k)! pk (1 − p)n − k

Tilt the pins with the slider and the pile slides over but keeps the same binomial form. Add rows and its outline approaches the smooth bell of the normal distribution, the same shape the dice sums grow into below.

Francis Galton designed the board for a lecture in 1874. It is also called a quincunx or a bean machine.

The law of large numbers

Flip a fair coin over and over. The share of heads swings widely at first, then settles closer and closer to one half.

Flip

Flips 0

Heads 0

Share of heads –

Heads minus tails 0

Latest flips

Share of heads

Heads minus tails

What follows a streak

: no flips yet.

A coin has no memory

After five heads in a row, tails can feel due. It is not. Each flip is independent of the ones before it, so the chance of heads stays 1/2 whatever just happened. Your own flips show it: after a run of heads, the next flip still comes up heads about half the time.

Then why does the share of heads settle? There is no pull toward balance. The gap between heads and tails usually grows as you keep flipping, roughly with the square root of the number of flips. The number of flips grows much faster, so the gap divided by the flips shrinks, and the share of heads closes in on 1/2. That is the law of large numbers.

Sums of dice

A single die gives each face the same chance. Add dice together and the middle sums pull ahead, because more combinations produce them.

Dice
Roll

Roll to see a sum.

Rolls 0

Average sum – exact 7

Every sum, exact and rolled
SumWaysProbabilityPercentYour rolls

Counting combinations

Two dice have 6 × 6 = 36 equally likely outcomes. A sum of 7 comes from six of them, so its probability is 6/36 = 1/6. A sum of 2 needs two ones: 1/36.

Sum
Sums of two dice

More dice are counted the same way. To reach a sum s with k dice, the first k − 1 dice must reach s − 1, s − 2, and so on down to s − 6, with the last die making up the difference. Add those six counts. As dice are added the shape rounds into a bell. The average sum of k dice is 3.5k, while the spread widens only with the square root of k.

Random walks

A walker takes steps of one unit, each in a random direction and independent of the last. How far away does it get?

On a line

Each step goes left or right with equal chance.

Walkers
Steps

Root mean square distance –

Square root of steps –

First walker ended at –

On a grid

Each step goes north, south, east or west with equal chance.

Steps

Distance from start –

Square root of steps –

Times back at the start –

Points visited –

The square root rule

Random steps partly cancel one another. After n steps the average squared distance from the start is exactly n, so the root mean square distance is √n. For 10,000 steps that is 100 units, nowhere near 10,000.

In 1921 George Pólya proved that a walker on a line or on a flat grid is certain to come back to its starting point eventually, however long that takes. On a three-dimensional grid the chance of ever returning drops to about 34%.

Seed and generator

The simulations draw their random numbers from xoshiro128**, a pseudorandom number generator. Each visit starts from a fresh random seed. Set your own, and the same clicks in the same order give the same doors, rooms, balls, flips, rolls and walks.