Except where otherwise noted, the contents of this document are Copyright 2013 Stuart Reges and Marty Stepp.
lab document created by Marty Stepp, Stuart Reges and Whitaker Brand
Goals for this problem set:
Randomobjects to produce random numbers
To use these methods, you need a variable of type
Random randy = new Random(); int aRandomNumber = randy.nextInt(10); // 0-9
||a random integer|
||a random integer between 0 (inclusive) and max (exclusive)|
||a random real number between 0.0 and 1.0|
Fill in the boxes to produce expressions that will generate random numbers in the provided ranges.
Assume that the following
Random variable has been declared:
Random rand = new Random();
|Example: a random integer from 1 to 5 inclusive:||
|a random integer from 0 to 3 inclusive:||
|a random integer from 5 to 10 inclusive:||
|a random integer from -4 to 4 inclusive:||
|a random even integer from 16 to 28 inclusive:
(Hint: To get only even numbers, scale up.)
Write a method named
makeGuesses that will output random
numbers between 1 and 50 inclusive until it outputs one of at least 48.
Output each guess and the total number of guesses made. Below is a sample
guess = 43 guess = 47 guess = 45 guess = 27 guess = 49 total guesses = 5
Try solving this problem in Practice-It! from the link above.