Events and Probability Spaces · Birthday Paradox

Lesson 5

Nikolai Chukhin · Alexander S. Kulikov

Let us see how the graph of the function \(p(n)=1-q(n)\), which is the probability that among randomly chosen \(n\) people there are at least two with the same birthday, grows.

from itertools import accumulate
import matplotlib.pyplot as plt
from operator import mul

num_days = 365

factors = [1 - i / num_days for i in range(num_days)]
prob_no_collision = list(accumulate(factors, mul))
prob_collision = [1 - p for p in prob_no_collision]

plt.plot(prob_collision)
plt.savefig('birthdays.png')

for n in (22, 23, 35, 99):
    print(f'The probability for {n} people '
          f'is {prob_collision[n - 1]}')

The probability for 22 people is 0.4756953076625502
The probability for 23 people is 0.5072972343239854
The probability for 35 people is 0.8143832388747152
The probability for 100 people is 0.9999996927510721