📜  标准正态分布(SND)– Java程序

📅  最后修改于: 2021-04-24 20:06:46             🧑  作者: Mango

标准正态分布是正态分布的特例。当正常随机变量的平均值为0标准差为1时,就会发生这种情况。标准正态分布的正态随机变量称为标准分数z分数
通过以下公式可以将正态分布值转换为标准正态分布值:

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

代码 –

// 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);
    }
}

输出 –

the Z-value obtained is: -2.4

生成随机标准正态函数–在Java使用nextGaussian():
nextGaussian()方法用于获取下一个随机,均值为0.0和标准差为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

以下示例显示Java.util.Random.nextGaussian()的用法:

代码 –

// 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);
    }
}

输出 –

The next Gaussian value generated is : -0.24283691098606316