# The Game Logic

Get an overview of our game's logic.

We'll cover the following

## The secret number

The game will generate a secret number that our player is supposed to guess. For that, weâ€™ll use Javaâ€™s random number generator method, Math.random(). More specifically, weâ€™ll use Math.random() * (max - min + 1) because this lets us specify a range for the random number. For example, if we want to generate a number between 40 and 70, weâ€™ll use Math.random() * (70 - 40 + 1).

Note: The method Math.random() * (max - min + 1) returns a floating number (a number with a decimal), not an integer.

## The guess number

Once weâ€™ve generated our secret number, we want the player to guess it. For that, weâ€™ll need the user to give their guess as input. In Java, we can take the userâ€™s input using Scanner.

When we take the input, weâ€™ll have to make sure that the user enters only the integer number and reject invalid input like a character or a double value.

### Taking input in Java

Note: Weâ€™ll use java.util.Scanner to take the userâ€™s input, but you donâ€™t need to know its details as it is not part of your AP CS A exam.

Letâ€™s see some code for clarity.

Get hands-on with 1200+ tech skills courses.