Groovy - random()


Advertisements

The method is used to generate a random number between 0.0 and 1.0. The range is: 0.0 =< Math.random < 1.0. Different ranges can be achieved by using arithmetic.

Syntax

static double random() 

Parameters

This is a default method and accepts no parameter.

Return Value

This method returns a double.

Example

Following is an example of the usage of this method −

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

When we run the above program, we will get the following result −

0.0543333676591804 
0.3223824169137166
groovy_numbers.htm
Advertisements