What is the probability that at least two people this room share the same birthday?
Is it something like \(\frac{27}{365} =\) 0.07
1 - Simulate 10,000 rooms with n = 27 random birthdays, and store the results in matrix where each row represents a room.
2 - For each room (row) compute the number of unique birthdays.
3 - Compute the average number of times a room has 40 unique birthdays, across 10,000 simulations, and report the complement.
birthday.prob = function(n.pers, n.sims) {
# simulate birthdays
birthdays = matrix(round(runif(n.pers * n.sims, 1,
365)), nrow = n.sims,
ncol = n.pers)
# for each room (row) get unique birthdays
unique.birthdays = apply(birthdays, 1, unique)
# Indicator with 1 if all are unique birthdays
all.different = (lapply(unique.birthdays, length) == n.pers)
# Compute average time all have different birthdays
result = 1 - mean(all.different)
return(result)
}
n.pers.param = n.pers
n.sims.param = 1e4
res1 = birthday.prob(n.pers.param,n.sims.param)
The simulated probability is 0.64