如何在 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模板网!
读取输入文件,最快的方法?read input files, fastest way possible?(读取输入文件,最快的方法?)
在 C++ 中读取格式化输入的最简单方法?The easiest way to read formatted input in C++?(在 C++ 中读取格式化输入的最简单方法?)
从 .txt 文件读取到 C++ 中的二维数组Reading from .txt file into two dimensional array in c++(从 .txt 文件读取到 C++ 中的二维数组)
如何在 C++ 中模拟按键按下How to simulate a key press in C++(如何在 C++ 中模拟按键按下)
为什么在 cin.ignore() 之后没有 getline(cin, var) 读取Why doesn#39;t getline(cin, var) after cin.ignore() read the first character of the string?(为什么在 cin.ignore() 之后没有 getline(cin, var) 读取
scanf 格式输入的 cin 类比是什么?What is the cin analougus of scanf formatted input?(scanf 格式输入的 cin 类比是什么?)