Java.lang.StrictMath.random() Method



Description

The java.lang.StrictMath.random() method returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.This method is properly synchronized to allow correct use by more than one thread.

Declaration

Following is the declaration for java.lang.StrictMath.random() method

public static double random()

Parameters

NA

Return Value

This method returns the pseudorandom double greater than or equal to 0.0 and less than 1.0.

Exception

NA

Example

The following example shows the usage of java.lang.StrictMath.random() method.

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      /* returns a double value with a positive sign,
      greater than or equal to 0.0 and less than 1.0 */
   
      double randomValue = StrictMath.random();    
      System.out.println("1st randomly generated number = "+ randomValue);

      System.out.println("2nd randomly generated number = "+ StrictMath.random());

      System.out.println("3rd randomly generated number = "+ StrictMath.random());
   }
}

Let us compile and run the above program, this will produce the following result −

1st randomly generated number = 0.9920868657769093
2nd randomly generated number = 0.15952532993970858
3rd randomly generated number = 0.26097639244001813

java_lang_strictmath.htm
Advertisements