1. Method description
Math.random() returns a double value of [0.0,1.0). Since the double value has higher precision, it can be regarded as random. Number, use (int) for type conversion to obtain an integer random number.
2. Example
public static void main(String[] args) { int max=100,min=1; int ran2 = (int) (Math.random()*(max-min)+min); System.out.println(ran2); }
Sometimes we need some randomly generated numbers for use, and this java method has a way to generate random numbers. What this article brings is the Math.random() method, which can randomly generate some random numbers of integers.
The basic data types of Java are divided into:
1. Integer type, used to represent the data type of integer.
2. Floating point type, a data type used to represent decimals.
3. Character type. The keyword of character type is "char".
4. Boolean type is the basic data type that represents logical values.
The above is the detailed content of How to generate non-repeating random numbers every time in java. For more information, please follow other related articles on the PHP Chinese website!