问题描述
有谁知道我怎么能轻松地生成以下用C的正态分布随机数/ C ++?
Does anyone know how I could easily generate random numbers following a normal distribution in C/C++ ?
http://www.mathworks.com/access/helpdesk/help/toolbox/stats/normrnd.html
我不希望使用任何加速的。
I don't want to use any of Boost.
我知道,克努特这个会谈的长度,但我没有他的手的书现在。
I know that Knuth talks about this at length but I don't have his books at hand right now.
推荐答案
箱穆勒变换是常用。此正确地产生具有正常分布的值。
The Box-Muller transform is what is commonly used. This correctly produces values with a normal distribution.
http://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution
http://en.wikipedia.org/wiki/Box_Muller_transform
数学很简单。您产生两个统一编号,并从那些你得到两个正态分布的数字。返回之一,保存等了随机数的一个请求。
The math is easy. You generate two uniform numbers and from those you get two normally distributed numbers. Return one, save the other for the next request of a random number.
这篇关于生成以下用C / C的正态分布随机数++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!