How many people do we need to have in a room to make it a favorable bet (probability of success greater than 1/2) that two people in the room will have the same birthday?
This is an example I read it from the book, “Introduction to Probability”. The solution is:
Assume that there are 365 possible birthdays for each person(ignore leap years). We must find the probability that have no duplication of birthdays.
For two people, it is…
For three people, it is…
For more people, it is…
So the probability that two people in the room will have the same birthday is…
It turns out that
Number of people, Probability that two ppl have same birthday
20 0.411438
21 0.443688
22 0.475695
23 0.507297 <-- the answer
24 0.538344
25 0.568700
Let’s Code
The Python code is:
def calc_prob(ppl_num):
"""
Calc the probability of that ppl have no duplication of birthdays.
"""
prob_no_dup = 1
if ppl_num > 1:
for i in range(1, ppl_num):
prob_no_dup *= (365. - i if i <= 365 else 0) / 365.
return 1. - prob_no_dup
And the plot is like:

Conclusion
It is tempting to guess that we would need about this number, or , but the answer is . From the chart we can see the probability that two people have same birthday is almost when there’re more than people in a room.
[code]