2 * Print a lookup table for Gaussian numbers with 4 entries on each
3 * line, formatted for inclusion in this file. Size is 2^bits.
7 print_gaussian_table(int bits
)
10 double invn
,fac
,x
,invgauss
,det
,dx
;
14 table
= (real
*)malloc(n
*sizeof(real
));
16 /* Fill a table of size n such that random draws from it
17 * produce a Gaussian distribution.
18 * We integrate the Gaussian distribution G approximating:
19 * integral(x->x+dx) G(y) dy
21 * G(x) dx + G'(x) dx^2/2 = G(x) dx - G(x) x dx^2/2
22 * Then we need to find dx such that the integral is 1/n.
23 * The last step uses dx = 1/x as the approximation is not accurate enough.
32 invgauss
= fac
*exp(0.5*x
*x
);
33 /* det is larger than 0 for all x, except for the last */
34 det
= 1 - 2*invn
*x
*invgauss
;
35 dx
= (1 - sqrt(det
))/x
;
44 printf("static const real *\ngaussian_table[%d] = {\n",n
);
48 printf("%14.7e",table
[i
+j
]);