Java random() method


Java random() method

Java Number类Java Number Class


random() method is used to return a random number, the range of random numbers is 0.0 =< Math.random < 1.0.

grammar

static double random()

parameter

  • This is a default method that 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() );
	}
}

Compile the above program and the output result is:

0.5444085967267008
0.7960235983184115

Java Number类Java Number Class