Simulating the Birthday Paradox on a given Set As a first step, we will simulate
ID: 3790897 • Letter: S
Question
Simulating the Birthday Paradox on a given Set
As a first step, we will simulate the problem on a set of size n, where n is provided as a parameter to our program.The overall goal is to repeatedly draw randomly from that set until an element has been drawn twice. We want to repeat this test a number of times, and see how many draws are required on average. We will also report the minimum and maximum value found, as well as the standard deviation.
By default, the size of the set to draw from is 365 elements, and the experiment is repeated 50 times. It is however possible to optionally specify both the size of the set and the number of elements from the command line.
Here is a sample run using the default values:
> java BirthdayParadox
We have run 50 experiments.
the minimum was 4
the maximum was: 49
the mean was: 23.8
the standard deviation was: 11.65
Here is another sample run, this time on a set of size 10,000, with 2,500 experiments:
> java BirthdayParadox 10000 2500
We have run 2500 experiments
the minimum was 4
the maximum was: 429
the mean was: 126.34
the standard deviation was: 66.25
As can be seen, for both mean and standard deviation, only two decimal are shown.
A detailed description of the classes can be found here:
Explanation / Answer
1st Method PROGRAM
Name=BIRTHDAY :ClrAllLists :Disp “NUMBER OF” :Disp “PEOPLE” :Input N :randInt(1, 365, N)->L1 :SortA(L1)
2nd Method PROGRAM
Name=BIRTHDAY :ClrAllLists :Disp “NUMBER OF” :Disp “PEOPLE” :Input N :randInt(1, 12, N)->L1 :randInt(1, 31, N)->L2 :100*L1+L2->L3 :SortA(L3, L1, L2)