Solution Review

Let’s look at the solution of the problem from the last lesson.

Task I: Generate the secret number

The task was to generate a random number to be guessed by the player.

We can use the formula Math.random() * (max - min + 1) to generate a random value between 0 and 100 (inclusive). Our max value is 100 and our min is 0.

Press + to interact
//Generating a random integer between 0 and 100 inclusive
int secret_number = (int) (Math.random() * (100 - 0 + 1));
...

Get hands-on with 1400+ tech skills courses.