MegaMan (megaman) wrote,
MegaMan
megaman

/**

1. An integer, seed, to start the random number generator (just as it was done for program 3 - InBetween).
2. An integer, numSharing, specifying how many people must share the same birthday in order to consider a trial successful.
3. An integer, maxPeople, specifying the maximum number of people "in the room".
4. An integer, numTrials, specifying the number of trials to run for each number of people.



psudo code:
create an array representing the days of the year
add birthdays
check to see if any day has more than one birthday in a day.
compute the probability of the having n people born on the same day out of the sample.


one trial:
create the array:
make a new array of 365 ints.
possibly initilize all to 0.
find the number of people. int maxPeople = [the number of people];
randomly add 1 to maxPeople number of days.
see how many birthdays are shared by numSharing
repete the trial numTrials times.

the math test
-------------------
*/



import java.util.Random;
//import tio.*;

class birth
{

public static void main(String[] args) {
System.out.print("What is maxpeople:");
int maxPeople = 300; //Console.in.readInt();
trial(maxPeople);
System.out.println("That was hella rockin!");

}

static void trial(int maxPeople)
{
int[] theYear = new int[365];
for(int mp = 0; mp < maxPeople; mp++)
{
int oneGuy = random.nextInt(365);
theYear[oneGuy] = theYear[oneGuy] + 1;
}

for(int i = 0; i < theYear.length; i++)
{
System.out.print( theYear[i]);
if (theYear[i] > 1)
{
System.out.println();
}
}
}






/**
This method returns a new Random (random number generator object).
If the array args is not empty, the first element is assumed to be
a string representation of an integer. The integer will be used to
"seed" the random number generator so that it generates a repeatable
string of pseudo-random numbers.
If the array args is empty, the random number generator is created
with a random seed (internally by the class Random).
@param args - an array that is either empty or starts with a string
representation of an integer - used to seed the random number
generator
@return a newly created (and seeded) random number generator
*/
static Random initializeDice(String[] args) {
if (args.length == 0) {
return new Random();
}
else {
return new Random(Integer.parseInt(args[0]));
}
}
}
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 3 comments