Groovy – random()

  • Post author:
  • Post category:Groovy
  • Post comments:1 Comment
random

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

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply