Hover over the menu bar to pick a physics animation.

Probability of Same Birthday

An interesting question when you have many people in the same area is whether two of them have the same birthday. It turns out, as this animation will show, that you need only about 23 people to have a 50% chance that two will have the same birthday. To begin, it is clear that when you have just two people, the probability is 1/365. For 3 or more people, the math gets more involved. The equation for the probability is

`P(p)=1-(365!)/[(365-p)!365^p]`

where p is the number of peopled sampled and ! denotes the factorial operation. It is easy to show from this equation that `P(2) =1/365` as expected. Let's work out the `P(p)` for `p=3`

`P(3)=365^3-((365)(365-1)(365-2))/(365^3)`
`P(3)=365^3-((365)(365^2-3*365+2))/(365^3)`
`P(3)=(3*365^2-2*365)/(365^3)`
`P(3)=3/365-2/365^2`

Let's consider how the number `3` comes about by looking at persons `a,b,c`. Matches can obviously be `a-b`, `a-c` and `b-c` so we get `P(3)=3/365` if we exclude the much smaller `2/365^2` term. Since computers don't generally provide factorials of numbers as high as 365, one must use Stirling's approximation , `S(n)`, for these factorials.

`n!~S(n)=sqrt(2*pi*n)(n/e)^n`

where `e=2.718` is the exponential base. Then we have for the factorial ratio:

`P(p)=1-(S(365))/(S(365-p)365^p)`

Inserting the expressions for `S(...)` and letting `y=365` we obtain:

`P(p)=1-(sqrt(2*pi*y)(y/e)^y)/(sqrt(2*pi*(y-p))((y-p)/e)^(y-p)y^p)`

The `2pi` expressions cancel and we can also express the `e` terms differently:

`(1/e)^y/(1/e)^(y-p)=(1/e)^(y-y+p)=(1/e)^p=e^(-p)`

and get a more compact equation for `P(p)`:

`P(p)=1-e^(-p)y^(y-p+1/2)/((y-p)^(y-p+1/2)`

The exponents in numerator and denominator are the same so we can re-write the expression:

`P(p)=1-e^(-p)(y/(y-p))^(y-p+1/2)`

which does not look like a very tractible expression since the computer's maximum double precision number is `10^(308)`. Howwever, the computer handles the very large exponents very nicely and `P(p)` yields excellent precision.

The learner may use the slider to adjust the number of people, p.

I have provided an animated numerical calculation of P(p). After pressing the Start button, you can see that this numerical result, `P(p)`, `(1.0-epsilon)` where `epsilon` slowly converges 0 after `p` becomes more than about 50.