Here's a short Delphi program that lists the probability that at least two people share a
common birthday in a room containing N people.
The phrase "at least" in probability problems is a cue to compute the probability of none and subtract that number
from 1. e.g. the probability that I have at least two socks of the same color in my drawer is 1- probability that there are not two socks of the same color.
In the birthday case, the probability that no two people share the same birthday out of
two people (let's call it P2), is 364/365.
I took one of the days, if you are not to share my day, yours had
better be on one of the other 364. Recall that by definition, probability of an
outcome is the number of cases where that outcome occurs divided by the total possible outcomes.
For three people the probability of none shared is P3=(364/365)*(363/365). For 4 the probability is
P4= P3*362/365. You first three guys eliminated 3 choices so I
have to choose one of the 362 remaining days if I'm not to share a birthday with any of
you. Etc, etc. etc.
We multiply these probabilities because of the rule of conditional probabilities, the probability of A and B both being true is the the probability that A is true times the probability that B is true, given the condition that A is true. This is usually written as P(A,B)=P(A)*P(B|A). In our birthday case, the probability that there are no shared birthdays among 4 people is the probability that there are no shared birthdays among the first 3 times the probability that the 4th doesn't match any of the others, once we know that they all have different birthdays. We need this last condition to ensure that we have only 362 choices for that 4th guy's birthday.
And again, remember that the probability of some shared birthdays is 1 - probability
of no shared birthdays. That's it.
So if after running this program you'll know that if you have 30 people in your class,
there is a greater than 70% chance that 2 celebrate the same. With 40
people, you can be 90% sure that at least two have the same birthday. I'll
take that bet.
Addendum Sept 2, 2003: The above discussion ignores the possibility that someone in the room may have a birthday on February 29 during a leap year. I have had the code including that possibility for several months, but I had a difficult time explaining the revised calculation. I finally tackled the write-up this weekend and posted it on a separate Shared Birthdays Leap year page. The downloadable programs below have been revised and now report statistics with and without leap year considerations.
Done Sept 2, 2003: By the way -- there is a small chance that someone in the room has a February
29 birthday . How should this affect the calculation?