//随机产生一个符合正态分布的数 u均数,d为方差
public static double Rand(double u, double d)
{
double u1, u2, z, x;
//Random ram = new Random();
if (d <= 0)
{
return u;
}
u1 = (new Random(GetRandomSeed())).NextDouble();
u2 = (new Random(GetRandomSeed())).NextDouble();
z = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2);
x = u + d * z;
return x;
}
C#生成一个符合正态分布(高斯分布)的随机数
时间: 2024-10-24 14:23:41