Question: 4. We can use the Math. random method to generate random integers. For example, Math. random generates a random integer greater than or equal to
4. We can use the Math. random method to generate random integers. For example, Math. random generates a random integer greater than or equal to 0 and less than 1. The expression Math.random6 generates random numbers between 0 and 5 throw of a die. In this lab assignment, you will use an array to test whether the random generator is fair; that is, whether each possible value is generated approximately the same number of times Your program should ask the user: How many random numbers should be generated? What is the number of values for each random draw? (e.g., 6) Make an array with one element for each possible outcome. Set each element to 0. Then keep calling the random number generator. If it returns a value v, then increment the counter belonging to v. After all numbers have been generated, print the counters. Here is a typical program run: How many random numbers do you want to generate? 1000 What is the number of values for each random draw? 10. 0 78 1 101 2 118 3 97 4 103 5 102 6 112 AVw 7 91 8 94 9 104
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
