Standard Normal Distribution (SND) – Java Program

The standard normal distribution is a special case of the normal distribution. It occurs when a normal random variable has a mean of 0 and a standard deviation of 1. The normal random variable of a standard normal distribution is called a standard score or a z score.
A conversion from Normally distributed to Standard Normally distributed value occurs via the formula,

Z = (X - u) / s
where:
Z = value on the standard normal distribution
X = value on the original distribution
u = mean of the original distribution
s = standard deviation of the original distribution

Code –

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to demonstrate the naive method
// of finding Z-value
  
import java.io.*;
import java.util.*;
  
class SDN {
    public static void main(String[] args)
    {
  
        // initialization of variables
        double Z, X, s, u;
        X = 26;
        u = 50;
        s = 10;
  
        // master formula
        Z = (X - u) / s;
  
        // print the z-value
        System.out.println("the Z-value obtained is: " + Z);
    }
}

chevron_right


Output –



the Z-value obtained is: -2.4

Generating a Random Standard Normal Function – Using nextGaussian() in Java :
The nextGaussian() method is used to get the next random, Normally distributed double value with mean 0.0 and standard deviation 1.0.

Declaration :
public double nextGaussian()
Parameters :
NA
Return Value :
The method call returns the random, Normally distributed double value
with mean 0.0 and standard deviation 1.0.
Exception :
NA

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

Code –

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to demonstrate the working
// of nextGaussian()
import java.util.*;
  
public class NextGaussian {
  
    public static void main(String[] args)
    {
  
        // create random object
        Random ran = new Random();
  
        // generating integer
        double nxt = ran.nextGaussian();
  
        // Printing the random Number
        System.out.println("The next Gaussian value generated is : " + nxt);
    }
}

chevron_right


Output –

The next Gaussian value generated is : -0.24283691098606316


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.