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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started