puzzle #1
In this lesson

Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.

Birthday problem

You will learn: Count collision opportunities and compare uniform with uneven category probabilities.

Start with: Events and probability

New to the notation? Start with the connected foundation for the underlying definitions and a worked example.

Under independent, uniformly distributed birthdays on 365 calendar days, 23 people are enough for the probability of at least one shared birthday to exceed one half. Leap days, dependence, and unequal day probabilities change the model.

With 23 people, probability of a shared birthday: theoretical 50.7% empirical 51.7% (2000 trials)
P(shared birthday) by group sizeuniform: n = 230.00.20.40.60.81.010203040506070group sizeP(shared birthday)

The filled black point is the exact probability; the open blue circle is the simulated frequency at the selected group size. The curve uses the selected day-probability model.

Three different matching questions

Event or quantityValue
Any pair among n people shares a day0.5072972
A designated person matches at least one of the other n−10.05857133
At least one of n people has calendar day 10.06115058
Expected number of matching pairs0.6931507
Rare-pair approximation: 1 − exp(−expected pairs)0.5000018

At weight one, all 365 days are equally likely. Larger weights give each of days 1–90 that many times the probability of each remaining day, then normalize all probabilities. This is a synthetic nonuniform model, not measured seasonality. Birthdays remain independent; twins and other dependence are outside this model. An expected pair count is not itself a probability.

Inspect the first simulated group
PersonDayPeople in group with this day
12291
211
31931
43591
53541
61031
72241
82641
91561
103641
111671
121792
13511
141481
15911
16571
171792
18251
191451
202801
211051
22701
23161
Black curve: exact model probability, calculated from the probability of distinct days. Blue dot: empirical rate from 2000 random groups of 23. The n=23 marker is the uniform-model crossover; nonuniform settings have a different curve.
P(collision)=1−∏k=0n−1365−k365P(\text{collision}) = 1 - \prod_{k=0}^{n-1}\frac{365-k}{365}

Why so few

The trick is counting pairs, not people. With n people there are n(n−1)/2n(n-1)/2 pairs. At n = 23 that’s 253 pairs — 253 chances for a match. Each individual pair has only a 1/365 chance of a collision, but many chances add up fast, although their dependencies mean we cannot multiply 253 independent non-match probabilities.

The formula above just tracks that directly: for each of the n people, the probability their birthday is new given all previous births is (365−k)/365(365-k)/365. Multiply those together for P(no collision); subtract from 1.

What to notice

  • The curve is non-linear — it rises slowly then accelerates. 50% arrives earlier than intuition suggests, 99% by just n = 57.
  • The empirical fraction fluctuates across seeded repetitions; its variance is P(1−P)/trials under the simulation model. Raising the trial count reduces Monte Carlo uncertainty.
  • This is why hash collisions become likely much sooner than hash-output size implies. For uniform independent 128-bit outputs, the generic collision scale is roughly 2^64 samples. This is a collision-search statement, not a statement that finding a preimage for a specified output takes only 2^64 attempts.

Derive the complement and its approximation

The first person can have any birthday. Conditional on all k previous birthdays being distinct, person k+1 avoids them with probability 1−k/365. Multiplying these conditional probabilities gives the chance that every birthday is distinct. The factors are conditional; they do not assert independence of pair-match events.

For group sizes small relative to 365, using log(1−x) ≈ −x gives:

P(any match)≈1−exp⁡(−n(n−1)2⋅365).P(\text{any match})\approx1-\exp\left(-\frac{n(n-1)}{2\cdot365}\right).

At n=23, the exact probability is 0.507297 and the approximation is about 0.500002. The expected matching-pair count is 253/365 ≈ 0.693151, which is neither of those probabilities. Groups with three equal birthdays contain three matching pairs but still count as only one group with a collision.

Match anyone, one person, or one day

Among 23 people, the chance that a designated person’s birthday matches any of the other 22 is 1−(364/365)22≈0.0585711-(364/365)^{22}\approx0.058571, far below 0.507297. The chance that at least one of all 23 people was born on a preselected calendar day is 1−(364/365)23≈0.0611511-(364/365)^{23}\approx0.061151. The demo reports these separately.

Make a prediction

With one person, can the any-pair probability be positive?

Explore the answer

No. There is no pair. But the chance of that person having a specified calendar day is 1/365 in the uniform model. At 366 people, a pair is certain under a 365-day model, by the pigeonhole principle.

Unequal birthdays

The weight control creates a synthetic population in which each of days 1–90 is more probable than each remaining day. The weights are normalized, and birthdays remain independent. The exact no-collision probability is n! times the sum of the products of probabilities over every n-day subset. A recurrence evaluates this without enumerating all subsets. The first-group table exposes actual sampled days and multiplicities.

For probabilities p₁,…,p₃₆₅, the expected pair count is (n2)∑dpd2\binom n2\sum_d p_d^2. A Poisson-style rare-pair approximation uses that count in 1−exp(−count), but it is not an exact formula for dependent pair indicators. The exact curve is retained to show the approximation’s error.

Make a prediction

Does weighting some days more heavily preserve the famous 23-person threshold?

Explore the answer

Not necessarily. The threshold depends on the complete birthday distribution and independence assumption. Increase the synthetic weight and compare the exact curve at the same group size; the default 23 marker describes only the uniform model.

Reference

Random Services: the birthday problem develops the finite-sampling complement formula. The weighted recurrence, designated-person calculation, and sample table state the specific extensions used here. They do not substitute simulated seasonality for measured birthday data.

Reset all settings