StrictMath random() Method in Java
The random() is an inbuilt method of StrictMath class in java which is used to get a double value with a positive sign that is greater than or equal to 0.0 and less than 1.0. random() method is accurately organized to acquiesce appropriate use by more than one thread. The values which are returned are adopted pseudorandomly with constant distribution from that range.
Syntax:
public static double random()
Parameters: The method does not accept any parameters.
Return Value: The method returns the pseudorandom double which is greater than or equal to 0.0 and less than 1.0.
Below programs illustrate the Java.lang.StrictMath.random() Method:
Program 1:
// Java praogram to illustrate the // Java.lang.StrictMath.random() Method import java.lang.*; public class Geeks { public static void main(String[] args) { double random_num = StrictMath.random(); System.out.println("Generated random number = "+ random_num); random_num = StrictMath.random(); System.out.println("Generated random number = "+ random_num); } } |
Generated random number = 0.7276560829796844 Generated random number = 0.6646167632286143
Program 2:
// Java praogram to illustrate the // Java.lang.StrictMath.random() Method import java.lang.*; public class Geeks { public static void main(String[] args) { double random_num = StrictMath.random(); System.out.println("Generated random number = "+ random_num); random_num = StrictMath.random(); System.out.println("Generated random number = "+ random_num); } } |
Generated random number = 0.5071995313935024 Generated random number = 0.6938224427158157
Recommended Posts:
- StrictMath log() Method In Java
- StrictMath tan() Method in Java
- StrictMath exp() Method in Java
- StrictMath pow() Method in Java
- StrictMath sin() Method in Java
- StrictMath cosh() Method in Java
- StrictMath toRadians() Method in Java
- StrictMath toDegrees() Method in Java
- StrictMath min() Method in Java with Examples
- StrictMath max() Method in Java With Examples
- StrictMath getExponent() Method In Java
- StrictMath floor() Method in Java
- StrictMath multiplyExact() Method in Java
- StrictMath log10() Method in Java
- StrictMath tanh() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



