随机高斯变量 [英] Random Gaussian Variables

查看:136
本文介绍了随机高斯变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一类在.NET的标准库,让我的功能来创建符合高斯分布的随机变量?

Is there a class in the standard library of .NET that gives me the functionality to create random variables that follow Gaussian distribution?

推荐答案

用箱穆勒变换贾勒特的建议是很好的一个快速和肮脏的解决方案。一个简单的实现:

Jarrett's suggestion of using a Box-Muller transform is good for a quick-and-dirty solution. A simple implementation:

Random rand = new Random(); //reuse this if you are generating many
double u1 = rand.NextDouble(); //these are uniform(0,1) random doubles
double u2 = rand.NextDouble();
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
             Math.Sin(2.0 * Math.PI * u2); //random normal(0,1)
double randNormal =
             mean + stdDev * randStdNormal; //random normal(mean,stdDev^2)

这篇关于随机高斯变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆