Class activity solutions

Author

Ciaran Evans

Here is full code for the class activity:

import numpy as np

# set a seed for reproducibility
np.random.seed(33)

days = np.arange(364) # days of the year
n_students = 30
nsim = 10000
results = np.zeros(nsim)

for i in range(nsim):
    birthdays = np.random.choice(days, n_students, replace=True)
    results[i] = len(np.unique(birthdays)) < n_students

np.mean(results)
0.7047