java.util.Random.nextDouble() Method



Description

The nextDouble() method is used to get the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Declaration

Following is the declaration for java.util.Random.nextDouble() method.

public double nextDouble()

Parameters

NA

Return Value

The method call returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Exception

NA

Example

The following example shows the usage of java.util.Random.nextDouble()

package com.tutorialspoint;

import java.util.*;

public class RandomDemo {
   public static void main( String args[] ) {
      
      // create random object
      Random randomno = new Random();
    
      // check next double value  
      System.out.println("Next double value: " + randomno.nextDouble());
   }      
}

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

Next double value: 0.2766104090778083
java_util_random.htm
Advertisements