void GaussRandom(long *seed, float *result) { double x1, x2, g1; double XA, XB, big_S; double radical; big_S=1.0; while(big_S >= 1.0){ XA = DoubleUniformRandom(seed); XB = DoubleUniformRandom(seed); x1 = 1.0 - 2.0 * XA; x2 = 1.0 - 2.0 * XB; big_S = x1*x1 + x2*x2; } radical = sqrt(-2.0*log(big_S)/big_S); g1 = x1 * radical; *result = float(g1); }
//------------------------------------------------ void GaussRandom(long *seed, std::complex<double> *result) { double x1, x2, g1, g2; double XA, XB, big_S; double radical; big_S=1.0; while(big_S >= 1.0){ XA = DoubleUniformRandom(seed); XB = DoubleUniformRandom(seed); x1 = 1.0 - 2.0 * XA; x2 = 1.0 - 2.0 * XB; big_S = x1*x1 + x2*x2; } radical = sqrt(-2.0*log(big_S)/big_S); g1 = x1 * radical; g2 = x2 * radical; *result = std::complex<double>(g1, g2); }
double GaussRandom(long* seed) { double u1, u2, g1; double UA, UB, S; double radical; new_start: UA = DoubleUniformRandom(seed); UB = DoubleUniformRandom(seed); u1 = 1.0 - 2.0 * UA; u2 = 1.0 - 2.0 * UB; S = u1 * u1 + u2 * u2; if (S >= 1.0) goto new_start; radical = sqrt(-2.0 * log(S) / S); g1 = u1 * radical; return (g1); }