Class Activity

Instruction: Work with a neighbor to answer the following questions. Solutions will be posted on the course website. To get started, download the class activity template file.

The birthday problem

Suppose we have a class of 30 students. What is the probability that there is at least one shared birthday?

  1. Use the np.arange function to create a 1-dimensional array, days, to store the days of the year (numbered 0 to 364)

  2. Use the np.random.choice function to randomly choose birthdays for the class (shared birthdays are possible, so use replace=True in the function!)

  3. Check the number of distinct birthdays (hints: the np.unique and len functions may be helpful!). Are there 30 distinct birthdays?

  4. Use a for loop to repeat the experiment nsim = 10000 times, making sure to store the results. What is the probability of at least one shared birthday?