Open In App

Java Math random() Method

Last Updated : 04 Jan, 2025
Comments
Improve
Suggest changes
37 Likes
Like
Report

The java.lang.Math.random() method returns a pseudorandom double type number greater than or equal to 0.0 and less than 1.0. When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression new java.util.Random. 

Declaration of Java Math random()

Below is the declaration of java.lang.Math.random() method is mentioned below:

public static double random()

Return Type

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

Java Math random() Method with Examples

The Math.random() method is often used for generating random values in Java.

Example 1:To show the working of java.lang.Math.random() method. 

Output:

0.5568515217910215

Example 2:To show the working of java.lang.Math.random() method. 

Now to get random integer numbers from a given fixed range, we take a min and max variable to define the range for our random numbers, both min and max are inclusive in the range.

Output:

6
8
10
10
5
3
6
10
4
2


Next Article
Practice Tags :

Similar Reads