3. METHOD
Programming Methodology
The simulation was written in the Java language5. A text file that lists
multiple trials with the following parameters serves as input to the
program, (defaults outlined here are geared to solving the problem in
question):
\ue000
Number of matches to be checked (default:K = 2)
\ue000
Number of trials (various >> values)
\ue000
Starting group size (default:N = 2)
\ue000
Group size increment (default: 1)
\ue000
Terminating probability (default: 0.5)
Assumptions:
\ue000
The group size will never be greater than 1,000.
\ue000
In the case that the starting value ofN is less thanK, you should
start the simulation withN =K. The reason is simple: How do
you possibly find three (i.e.K) matches in a group of two (i.e.N)
persons?
Beginning with group size ofN = 2 people, we initialise an array with the
random birthdays ofN = 2 people; (the random number generator is being
seeded with the current time). We compare every pair wise (number of
matches K = 2) combination of people in the group of N = 2 and check the
existence of any two persons having the same birthday.
This will be repeated number of trials times with different groups of two
people. If the average occurrence of two persons having the same birthday
in these one thousand trials exceeds 0.5 (i.e. the probabilityP), the
simulation terminates. Otherwise,N is incremented by group size
increment = 1, and the entire simulation of one thousand trials is repeated
with randomized groups of (starting group size = 2) + (group size
increment = 1) people.
The flexibility in reading in values from a file that control the execution of
the algorithm allows us to evaluate numbers of people for various
probabilities and/or enumerate possible combinations of more than two
persons, differing numbers of trials and matches, and check for shared
birthdays, for example. A review of the Java source code in Appendix 2
should reveal other variations.
For each trial, a number of random birthdays are generated and placed into
an array; (here, we use the Julian Date format, 1\u2026365). These birthdays
are sorted and then iterated through to find the same values in consecutive
elements in the array, denoting a success. Once the trials have completed
running, the probability is evaluated as6:
currProbability = numSameBirthday / numTrials
4. RESULTS & DISCUSSION
With the availability of having an input file, multiple case scenarios can be
generated. Table 1 is an example of sample data was available on the
input file, (as per aforementioned format in Section 3):
Leave a Comment