Home >>Java Math Methods >Java Math.random() Method
The Math.random() in Java Math is used to return a double type number pseudorandom greater than or equal to 0.0 and less than 1.0. The random number generated by default always between 0 and 1.
public static double random( )
It is used to returns a pseudorandom double value greater than or equal to 0.0 and less than 1.0.
public class MyClass
{
public static void main(String[] args)
{
double x = Math.random();
double y = Math.random();
System.out.println(x);
System.out.println(y);
}
}
public class MyClass
{
public static void main(String[] args)
{
double x = Math.random() * 15;
double y = Math.random() * 15;
System.out.println(x);
System.out.println(y);
}
}