Question: Help with Java! There are two ways to add Randomness to our programs. We used the Random class, however, there is also a Random as

Help with Java!

There are two ways to add Randomness to our programs. We used the Random class, however, there is also a Random as part of the Math class. Math.random() returns a double between 0.0 and 1.0 exclusive (will never return 1) Random randomGenerator = new Random(); //requires an import statement int numb = randomGenerator.nextInt(10); //produces a random int between 0 and 10 exclusive (will never return 10)

Use each of these to produce a random int in the range 21 to 55 inclusive (both 21 AND 55 may be returned)

a. Using Math.random()

b. Using Random class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!