Home » Java programming language

Java Random nextGaussian() Method with Example

Random Class nextGaussian() method: Here, we are going to learn about the nextGaussian() method of Random Class with its syntax and example.
Submitted by Preeti Jain, on March 23, 2020

Random Class nextGaussian() method

  • nextGaussian() method is available in java.util package.
  • nextGaussian() method is used to generate the next pseudo-random Gaussian double value with mean 0.0 and standard deviation 1.0 from this Random Value Generator.
  • nextGaussian() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • nextGaussian() method does not throw an exception at the time of returning double.

Syntax:

    public double nextGaussian();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is double, it returns next pseudo-random Guassian distributed double value with mean and standard deviation from this Random Generator.

Example:

// Java program to demonstrate the example 
// of double nextGaussian() method of 
// Random

import java.util.*;

public class NextGuassianOfRandom {
 public static void main(String args[]) {
  // Instantiates Random object
  Random ran = new Random();

  // By using nextGuassian() method is
  // to return double guassian pseudo-random
  // value with mean 0.0 and SD 1.0 by
  // using Random Value Generator
  double val = ran.nextGaussian();

  // Display val
  System.out.println("ran.nextGaussian(): " + val);
 }
}

Output

RUN 1:
ran.nextGaussian(): 1.1146938453650543

RUN 2:
ran.nextGaussian(): -0.23741062599148818

RUN 3:
ran.nextGaussian(): 0.147051482639119


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.