Random numbers can be generated through the random() method.
The random() method is used to return a random number, the range of random numbers is 0.0 =< Math.random < 1.0. It is a default method and does not accept any parameters.
(Recommended video tutorial: java video)
Code sample:
public static void main(String[] args) { int max=100,min=1; int ran2 = (int) (Math.random()*(max-min)+min); System.out.println(ran2); }
Recommended tutorial: java entry program
The above is the detailed content of How to generate random numbers in java. For more information, please follow other related articles on the PHP Chinese website!