java.util.Random.nextGaussian() Method



Description

The nextGaussian() method is used to get the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Declaration

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

public double nextGaussian()

Parameters

NA

Return Value

The method call returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Exception

NA

Example

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

package com.tutorialspoint;

import java.util.*;

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

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

Next Gaussian value: -0.6697160313274964
java_util_random.htm
Advertisements