Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java random() Method

Java random() Method

Java Number ClassThe Java Number class


The random() method returns a random number in the range 0.0 =< Math.random < 1.0.

Syntax



static double random()

Parameters

Return Value

The 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

(

)

)

;

}

}

Compile the above program; the output is:



0.5444085967267008

0.7960235983184115


Java Number ClassThe Java Number class