normal-distribution

Generate random numbers following a normal distribution in C/C++

心不动则不痛 提交于 2019-11-26 01:57:16
问题 How can I easily generate random numbers following a normal distribution in C or C++? I don\'t want any use of Boost. I know that Knuth talks about this at length but I don\'t have his books at hand right now. 回答1: There are many methods to generate Gaussian-distributed numbers from a regular RNG. 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,

Converting a Uniform Distribution to a Normal Distribution

被刻印的时光 ゝ 提交于 2019-11-26 00:36:13
问题 How can I convert a uniform distribution (as most random number generators produce, e.g. between 0.0 and 1.0) into a normal distribution? What if I want a mean and standard deviation of my choosing? 回答1: The Ziggurat algorithm is pretty efficient for this, although the Box-Muller transform is easier to implement from scratch (and not crazy slow). 回答2: There are plenty of methods: Do not use Box Muller. Especially if you draw many gaussian numbers. Box Muller yields a result which is clamped