Recall that simulations involving the repeated use of a random number generator to reproduce a probabilistic event are called Monte Carlo simulations (after one of the world’s most famous gaming casinos). In this exercise, you are to find the probability that at least one people in a room with n people have birthdays that fall on January 1st. Assume that there are 365 days in a year and assume further that the chance of a person being born on each day of the year is the same. A single trial experiment consists of filling an array of size n with integers that are randomly distributed from 1 through 365 (with 1 denote January 1st). If any one element in the array has the value 1, then we say that the trial is true. Thus a true trial corresponds to the case when at least one people in the room was born on January 1st. Simulate the probability by running 10,000 trials with n people in the room. Do this for n = 2, 3, …, 100. You can use the expression
(int)(t.NextDouble() * 365 + 1) // t is a Random object
to compute the day of birth for each person. The number of true trials divided by 10,000 is the computed simulated probability.
The output of your program should be as following:
Number of people Probability with same birthday
0.xx
… …
100 0.xx