Easy Tutorial
❮ Java Object Clone Java Arraylist Lastindexof ❯

Java random() Method

Java Number Class


The random() method is used to return a random number, where 0.0 <= Math.random < 1.0.

Syntax

static double random()

Parameters

-

This is a default method and does not accept any parameters.

Return Value

This method returns a double value.

Example

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

Compiling the above program will produce the following result:

0.5444085967267008
0.7960235983184115

Java Number Class

❮ Java Object Clone Java Arraylist Lastindexof ❯