random() Function in Java


Description : It returns the random number between 0 and 1.

Return Data Type : It returns double type value.

Syntax : <return_data_type> <variable_name> = Math.random();

Example

public class RandomExample {
    public static void main(String[] args) {
        
        System.out.println(Math.random());
        System.out.println(Math.random());
        
    }
}

Output

0.015177751672932782
0.1044856441489187