subject

The goal of this lab is to conduct an experiment to test the Birthday Paradox, vhich states that if 23 people gather, the chances are 50-50 that there are two people in the group having the same birthdays This days; that is, for any day of the year, the proportion of the people born on that day is 1/365 of the entire population. Under these assunptions, the probability that randomly selected 23 people have distinct birthdays from each other is: 365 364* * 343 In the denominator, there is no constraint about the birthdays; each person picks up one birthday from the 365 possibilities. In the numerator, the 23 people select birthdays one after another, so that no tvo have the sane birthdays: the first person has 365 possibilities, the second has 364 because he/she must not pick the one that the first person has chosen, the third person has 363 because he/ahe nust not pick the ones that the first and the second persons have chosen, and so on. The fraction is about 0.50, so the chances are almost 50-50 that there are two people having the same birthdays The centerpiece of the code is a method, oneTrial, that, given a number of people as its paraneter, randomly selects birthdays for those people and produces for each day how many people have chosen to have that birthday. More formally, the method has the number of people, nPeople, as its formal parameter and returns an int array. The method firat instantiates an array of 365 elements, say theCounts. Then, for nPeople tines (using a for-loop)the method selects a random integer between 0 and 364, and then increases the element of thecounts at the selected integer. After that it returns the array thecounts After receiving the return value of oneTrial, we examine the alots of the array for an entry greater or equal to 2. Such a alot indicates the existence of multiple having the same birthdays. We give this task to a nethod hasAHit. This nethod has its formal parameter an integer array and returns a boolean. Using a for-loop, the method scans the slots of the fornal paraneter. On encountering a slot value >2, the method returns true, thereby ignoring the remainder of the code in the method. After the for-loop, the method returns false, indicating that no slot -2 has been encountered Using the above two methods, we write another method, experiment1. The method experimentl has two formal paraneters. The first is an int by the name of nPeople, which is loop to count the executions of oneTrial. After each execution, w feed the return array of oneTrial to hasABit. If hasAHit returns true, we increase the value of a double proportion of the repetitions in which the random birthday selections generated multiple people having the sane birthdays. The method experimentl reports this ratio before The main method receives the quantities for nPeople and nReps and calls experimentl with these two values To print the average, use ".3f" in printf so that exactly three digits appear after the decinal point.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:30
Is a string of code written to hurt others by damaging or destroying
Answers: 1
question
Computers and Technology, 23.06.2019 04:20
4. a1. vince owns a television repair shop that is insured undera commercial package policy. the policy includes thebuilding and personal property coverage form and thecauses-of-loss broad form. the declarations page indicatesthat coverage applies to both the building and the namedinsured's business property. explain whether or not thefollowing losses would be covered under his policy.a. a fire occurs on the premises, and the building isbadly damaged.b. a burglar steals some money and securities from anunlocked safe.c. a business computer is damaged by vandals whobreak into the shop after business hours.d. a tornado touches down near the store. several tel-evision sets of customers in the shop for repair aredamaged in the storm.til
Answers: 2
question
Computers and Technology, 24.06.2019 07:00
Selective is defined as paying attention to messages that are consistent with one’s attitudes and beliefs and ignoring messages that are inconsistent.
Answers: 1
question
Computers and Technology, 24.06.2019 08:30
Why might you choose to create a functional resume
Answers: 1
You know the right answer?
The goal of this lab is to conduct an experiment to test the Birthday Paradox, vhich states that if...
Questions
question
Mathematics, 02.01.2020 23:31
question
Mathematics, 02.01.2020 23:31
Questions on the website: 13722362