public double GetGaussDistributeRandom(double miu, double sigma2) // 均值 方差
{
Random ran = new Random(GetRandomSeed());
double r1 = ran.NextDouble();
double r2 = ran.NextDouble();
double r = Math.Sqrt((-2) * Math.Log(r2)) * Math.Sin(2 * Math.PI * r1);
double result = miu + sigma2 * r;
Console.WriteLine(result);
return result;
}
public static int GetRandomSeed() //产生随机种子
{
byte[] bytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
C#生成高斯分布随机数
最新推荐文章于 2024-07-17 20:02:36 发布