random() in Java

random(): This method is available in the Math class of Java.

Syntax:

double java.lang.Math.random()

This method does not take any arguments as its parameters. This method returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.

Returned values are chosen pseudo randomly with (approximately)uniform distribution from that range.

Returns: A pseudo-random double greater than or equal to 0.0 and less than 1.0.

Approach

Java

public class Random {
    public static void main(String[] args) {

        System.out.println(Math.random());

    }
}

Output:

Any random value in the range 0.0 to 1.0 (i.e 0.7532466910103461).

No comments:

Post a Comment