Java – Create Random Gaussian Value
To create a random Gaussian value in Java, use Random.nextGaussian() method. Create java.util.Random class object and call nextGaussian() method on this object. nextGaussian() returns a randomly generated Gaussian value.
In the following example, we will create a random Gaussian value using nextGaussian() method.
Java Program
</>
Copy
import java.util.Random;
public class Example{
public static void main(String[] args) {
Random random = new Random();
double g = random.nextGaussian();
System.out.println("Next random gaussian value is : " + g);
}
}
Output
Next random gaussian value is : 0.05262116402960923
Reference to Random.nextGaussian() method for syntax and more examples.
Conclusion
In this Java Tutorial, we learned how to create a random Gaussian value using java.util.Random.nextGaussian() method.