问题描述
如何在 C 或 C++ 中轻松生成服从正态分布的随机数?
How can I easily generate random numbers following a normal distribution in C or C++?
我不想使用任何 Boost.
I don't want any use of Boost.
我知道 Knuth 详细谈到了这个问题,但我现在手头没有他的书.
I know that Knuth talks about this at length but I don't have his books at hand right now.
推荐答案
生成的方法有很多来自常规 RNG 的高斯分布数.
Box-Muller 变换 是常用的.它正确地产生具有正态分布的值.数学很容易.您生成两个(均匀)随机数,并通过对它们应用公式,您会得到两个正态分布的随机数.返回一个,并将另一个保存为下一个随机数请求.
The Box-Muller transform is commonly used. It correctly produces values with a normal distribution. The math is easy. You generate two (uniform) random numbers, and by applying an formula to them, you get two normally distributed random numbers. Return one, and save the other for the next request for a random number.
这篇关于在 C/C++ 中生成服从正态分布的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)