Java Random - nextDouble() Method
The java.util.Random.nextDouble() method returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
Syntax
public double nextDouble()
Parameters
No parameter is required.
Return Value
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
Exception
NA
Example:
In the example below, the java.util.Random.nextDouble() method is used to get pseudorandom number, uniformly distributed double value between 0.0 and 1.0.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a random object Random rand = new Random(); //printing uniformly distributed double random numbers for(int i = 0; i < 5; i++) System.out.println("Next Double Value: " + rand.nextDouble()); } }
One of the possible outcome is given below:
Next Double Value: 0.5086559355994734 Next Double Value: 0.13016283736554546 Next Double Value: 0.3692908714197346 Next Double Value: 0.24406924527560225 Next Double Value: 0.22947266175033265
❮ Java.util - Random