Math.random()
Returns a double greater than or equal to 0.0 and less than 1.0 .
Syntax
Math.random()
Output is a double.
System.out.println(Math.random());
Output will be 0.7, different each time we run the above code.
Random number over a range of Numbers
We can specify a range, say 100 to 200 and get random numbers between them.
int max=200, min=100;
System.out.println((int) (Math.random() * (max-min)+1)+min);
« All Math functions
« Java
This article is written by plus2net.com team.
plus2net.com