Tutorials Point


  Java Basics
  Java Object Oriented
  Java Advanced
  Java Useful References
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java - random() Method


previous next AddThis Social Bookmark Button


Description:

The method is used o 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:

Here is the detail of parameters:

  • NA

Return Value :

  • Return value is a double

Example:

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

This produces following result:

0.16763945061451657
0.400551253762343

Note: Above result would vary every time you would call random() method.



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names