Skip to main content

Chapter 5b - Randomness - Continued

In the previous lecture we learnt about Random using nextInt() Here are some other random methods that you can use.

Other random Methods


Mini quiz β€” more Random methods​

Quiz

More Random methods

1 / 2

rand.nextDouble() returns a value in which range?

Pick an answer to see if you are right.


Challenge: percent to a letter​

Given a random-looking percent (0-99, passed in as if from rand.nextInt(100)), print "low" for under 33, "mid" for 33-65, "high" for 66 and up.


Exercises​

Activity: Pick from a list

Write letterFor(int index) that returns "A", "B", "C", or "D" for index values 0, 1, 2, 3 (as if the index came from rand.nextInt(4)).