RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gausrand.cpp
Go to the documentation of this file.
1 //
2 // File = gausrand.cpp
3 //
4 
5 #include "gausrand.h"
6 #include "uni_rand.h"
7 #include <math.h>
8 
9 double
10 GaussRandom(long* seed)
11 {
12  double u1, u2, g1;
13  double UA, UB, S;
14  double radical;
15 
16 new_start:
17  UA = DoubleUniformRandom(seed);
18  UB = DoubleUniformRandom(seed);
19  u1 = 1.0 - 2.0 * UA;
20  u2 = 1.0 - 2.0 * UB;
21  S = u1 * u1 + u2 * u2;
22  if (S >= 1.0)
23  goto new_start;
24  radical = sqrt(-2.0 * log(S) / S);
25  g1 = u1 * radical;
26  return (g1);
27 }
double GaussRandom(long *seed)
Definition: gausrand.cpp:10
complex sqrt(const complex _z)
Definition: complex.h:148
double DoubleUniformRandom(long *seed)
Definition: uni_rand.cpp:37