Due: November 9, 2023
Points: 30
The birthday problem asks how many people must be in a room so that the probability of two of them having the same birthday is 0.5. This problem has you explore it by simulation. Basically, you will create a series of lists of random numbers of length n = 2, …, and look for duplicates. You will do this 5000 times for each length. For each length, count the number of lists with at least 1 duplicate number; then divide that number by 5000. That is the (simulated) probability that a list of n generated numbers has at least one duplicate. As the random numbers you generate are between 1 and 365 (each one corresponding to a day of the year), this simulates the birthday problem.
Now, breathe deeply and calm down. We will do this in steps!
>>> hasduplicates([1, 2, 3, 4, 5, 5, 2])↵ True >>> hasduplicates([1, 2, 3, 4, 5, 6, 7])↵ False
For 2 people, the probability of 2 birthdays is 0.00220 For 3 people, the probability of 2 birthdays is 0.00880 For 4 people, the probability of 2 birthdays is 0.01680 For 5 people, the probability of 2 birthdays is 0.02940 For 6 people, the probability of 2 birthdays is 0.03940 For 7 people, the probability of 2 birthdays is 0.05900 For 8 people, the probability of 2 birthdays is 0.06840 For 9 people, the probability of 2 birthdays is 0.09700 For 10 people, the probability of 2 birthdays is 0.12360How many people are needed so that the probability of two of them with a birthday in common is over 0.9? How many are needed such that the probability of two of them having the same birthday is at least 0.5? Put these answers into a comment at the head of the file.
Hint: Don’t be surprised if your probabilities are slightly different than the ones shown in the sample output. As randomness is involved, it is very unlikely your numbers will match the ones shown here.
To turn in: Please call your program bday.py and submit it to Canvas
|
ECS 235A, Computer and Information Security Version of October 30, 2023 at 10:13PM
|
You can also obtain a PDF version of this. |