1. Engineering
  2. Computer Science
  3. please help in java please...

Question: please help in java please...

Question details
Please help in java please
2) The Random class allows us to generate pseudorandom numbers (and other things). A sequence of pseudorandom random numbers looks like random sequence of numbers but is actually computed with a deterministic algorithm using a seed. If you use the same seed you get the exact same sequence of numbers. If the seed is chosen randomly then a good pseudorandom number generator will be indistinguishable from a truly random number generator. For our purposes, we wont worry about truly random numbers. (If you are securing a website you would want to use truly random numbers.) Modify the method called public static void rollRandomDice(long seed) in the Tutorial02 program. Be sure to import the Random class. You do this by adding the line import java.util.Random; between your package line and your class declaration line in the TutorialO2 java file. Your method will create two Random objects. You will create your dice (random objects) as follows: Random diel new Random (); Random die2 new Random );
Each random object will be used to simulate a fair die (6-sided die). Using the nextint method, you will roll each die and add up their face values. Consult the API to see how to use the method to get values from 1 to 6 (inclusive), https://docs.oracle.com/en/avaliavase/11/docs/api/ava base/iava/util/Random.html The distribution of values (if each die is fair) is given at the end of this document. You can also see the distribution at https //mathinsight.ora/media/image/limage/two dice distribution.pna You Roll the dice 10000 times and record how many times each total (sum of face values) is rolled. Hint: Use an array of size 11 (since there are 11 possible outcomes ranging from 2 to 12) to record the frequency of each rolled total (sum of the two dice). Note that when you called the rollRandomDice method, you need to pass a seed value. It is not used yet so just pass any value you want. Print, to System.out, the frequency distribution you get after all the dice rolls. Is it as expected (e. is it the same as the plot shown in the link above)?
Question: Is it as expected (i.e, is it the same as the plot shown in the link above)? Now go back and after you create each die, set the seed for each using diel.setSeed (seed); die2.setSeed (seed); Here seed is the value passed as input to the method. What happened to your distribution? What happens if you change this to diel.setSeed (seed) die2.setSeed (seed+1) Can you explain the differences? ote: In practice, pseudorandom numbers are usually good enough. Obtaining truly random numbers is expensive observ ing nature: measuring radioactive decay, observing microscopic temperature fluctuations of the cpu or other various electromagnetic/quan always possible to generate enough truly random numbers for our needs. Only some applications require truly random numbers though (ike when securing a banks website). Using a pseudorandom sequence with a single truly random seed os often good enough. For us, we usually wont even worry the seed tum phenomena. It is not 8 8
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution