Random Numbers

Write down the answers first. Click the check to check your answer and to hide the answer.

1. Given the code below, what values could number have?
Integer number=RandomUtilities.nextIntegerFromAToBExclusive(0,3) answer

1 or 2, because it is from 0 to 3 exclusive

2. Given the code below, what values could num have?
Double num=RandomUtilities.nextDoubleInRange(0.0,1.0)+10; answer

A random value from 10.0 to 11.0

3. Given the code below, what values could num have?
Integer number=RandomUtilities.nextIntegerFrom0ToNExlusive(10); answer

A random value of 2, 3, 4, 5, 6, 7, 8 or 9

4. In the code below, how many different values can num have?
answer

11: 0,1,2,3,4,5,6,7,8,9,10

5. In this code, what does the bear comlain about most?
answer

He says I'm tired about 60% of the time.

6. If you want num to represent flipping a coin, what value should you give num? answer

Any 2 values will work:

7. If you want to select a random amount to jump, what type should you use? answer

double

8. If you want to select a random number of times to jump, what type should you use? answer

integer

9. Which has more values RandomUtilities.nextIntegerFromAToBExclusive( 1, 3 ); or RandomUtilities.nextIntegerFromAToBInclusive( 1, 3 ); answer

Inclusive: it includes the values 1, 2, 3. Exclusive is just 2

10. Integer sayIt = RandomUtilities.nextIntegerFromAToBInclusive( 0, 3 );
A loop executes sayIt times. Is it possible that the loop exceutes 0 times? answer

Yes, sayit can be 0.

Please review the materials for any questions you miss.

NEXT: