我正在使用 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;
我犯了一个明显的错误吗?