r*****t 发帖数: 286 | 1 ☆─────────────────────────────────────☆
whistleruk (whistleruk) 于 (Fri Feb 9 15:02:53 2007) 提到:
1。给出uniform()在每次调用gasdev()过程中被调用次数的估计。
double uniform(long *seed);
/* uniform() returns a uniform random variable in (0,1) */
double gasdev(long *seed)
/* Returns a normal random variable */
{
static int iset = 0;
static double gset;
double fac, rsq, v1, v2;
if (iset == 0) {
do {
v1 = 2.0 * uniform(seed) - 1.0;
v2 = 2.0 * uniform(seed) - 1.0;
rsq = v1 * v1 + v2 * v2;
} while (rsq >= 1.0 || rsq = |
|