可能重复:
Implementing Box-Mueller random number generator in C#
我正在使用Box-Muller变换方法生成正态分布的随机数:
do {
rand1 = 2*(rand()/(double)RAND_MAX)-1 ;
rand2 = 2*(rand()/(double)RAND_MAX)-1;
distSqr = rand1 * rand1 + rand2 * rand2;
} while (distSqr >= 1 );
mp1 = sqrt((-2*log(distSqr))/distSqr);
res = rand1 * mp1;
norm_dist=res*var+mean;
我正在犯一个明显的错误吗?