Birthday problem or birthday paradox is to compute the probability that at least two people have the same birthday (regardless the year of birth) for a group of n people. Intuitively, it's odd when two or more people happened to have the same birthday. But is it really that rare?
Let's think about it statically.
For n people, the probability of no one having the same birthday is:
On the other hand, the probability of two or more people having the same birthday is:
So, at what point of n will p(SameDay) greater than p(NoSameDay)? Namely, for how many people in a group, it's more likely having two or more people sharing the same birthday than no one sharing the same birthday.
Let's find out the answer with Python.
First I declared one function to calculate p(NoSameDay)
Then created another function to calculate p(SameDay)
Now, I will use a while loop to find out at what point of n will p(SameDay) be greater than p(NoSameDay).
Here is the result.
When there are 23 people,it's more likely 2 people having the same birthday!!The probability of at least 2 people having the same birthday is 0.51The probability of no one having the same birthday is 0.49
It shows when there are 23 people in a group, it more likely to have 2 or more people share the same birth. The correspond probability is 0.51, and the probability of no one share the same birthday is 0.49.
Finally, let's check the probability visually. I used matplotlib to plot these two probability for n, when n is from 1 to 100. First, I used a for loop to calculate the probabilities and put them in lists.
Now show the probability visually.
The plot is like this.
We can see at the point of n=23, the lines cross, and after n being greater than 60, p(SameDay) is almost equals to 1 and p(NoSameDay) is almost equals to 0. Hence, at the point of n > 60, it is actually odd that no one shares the same birthday.