Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java How To Generate Random Numbers?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___.random();How To Generate a Random Number
Math.random() returns a random number between 0.0 (inclusive), and 1.0 (exclusive):
Math.random();To get more control over the random number, for example, if you only want a random number between 0 and 100, you can use the following formula:
int randomNum = (int)(Math.random() * 101); // 0 to 100Related Pages
Java Math Reference
Java Type Casting