gran2.cc.txt
来自「压缩文件中是Error Correction Coding - Mathemat」· 文本 代码 · 共 29 行
TXT
29 行
/**********************************************************************/
/* Generate two unit-variance Gaussian random numbers.
This function calls rand(), so you can control the seed using
void srand(unsigned int seed);
Following Numerical Recipes
*/
/* Copyright 2004 by Todd K. Moon
Permission is granted to use this program/data
for educational/research only
*/
#include <stdlib.h>
#include <math.h>
void gran2(double &r1, double &r2)
{
double rsq, v1, v2, fac;
do {
v1 = 2*(rand()/(double)RAND_MAX) - 1;
v2 = 2*(rand()/(double)RAND_MAX) - 1;
rsq = v1*v1 + v2*v2;
} while(rsq > 1 || rsq == 0);
fac = sqrt(-2*log(rsq)/rsq);
r1 = v1*fac;
r2 = v2*fac;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?