Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Please help in java please image text in transcribed
image text in transcribed
image text in transcribed
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 won't 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 bank's website). Using a pseudorandom sequence with a single truly random seed os often good enough. For us, we usually won't even worry the seed tum phenomena. It is not 8 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago