Description
The method is used to generate a random number between 0.0 and 1.0. The range is: 0.0 =< Math.random < 1.0. Different ranges can be achieved by using arithmetic operations.
Syntax
static double random()
Parameters
Here is the detail of parameters −
- This is a default method and accepts no parameter.
Return Value
- This method returns a double.
Example
public class Test {
public static void main(String args[]) {
System.out.println( Math.random() );
System.out.println( Math.random() );
}
}
This will produce the following result −
Output
0.16763945061451657 0.400551253762343
Note − The above result will vary every time you call random() method.
java_numbers.htm