I'm retired now, but when I was a teacher I used to have classes with exactly 30 students. At the beginning of the school year I told these classes: “I bet at least two of you have the same birthday.”
I was proven right in 70% of the cases.
For many people, this result is counterintuitive. They call it the birthday paradox.
Can you explain this good result?
To calculate the probability that there are two or more students with the same date of birth, it is easiest to first calculate the probability that there are no students that have the same date of birth.
The chance that two students A and B do not have the same birthday is about 364/365. I neglect leap years - this hardly effects the results. The chance that a third student C has another birthday than both A and B is 363/365. So, the chance that those three students all have another birthday is 364/365 × 363/365. The chance that five students all have different birthdays is 364/365 × 364/365 × 362/365 × 361/365.
This may sound very reasonably to you. The paradox is that when you calculate this number for 23 students, the chance is already 50%. For 70 students it is almost 100%.
In reality, the chances will be even higher because birthdays are not spread evenly throughout the year.
You can extend the formules above to a larger number of students, but it is also very easy to derive a general equation for n students. This equation reads: p(two or more same birthdates in class with n students) = .
According to this equation, the chance of at least two students having the same birthday in each of my classes is just over 70%.
If you want to calculate the result for the number of students in your class, using a programming language you may run into problems because intermediate results will cause an overflow. With calculaters there is no problem.
When you click a button below, you can see how to do this for a number of popular calculators and programs.
No problems with Excel
In Python Decimal prevents overflow. I modified the equation, so no binom is needed. This works well with Python 3.7
In Matlab or GNU Octave: no problems, but disable warnings. (nchoosek = n choose k)