diff options
author | Thomas White <taw@physics.org> | 2011-05-11 17:27:11 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:26 +0100 |
commit | bc5fd6907120554ae0649032b5f88461c2b1788f (patch) | |
tree | 19c6cb9c558e4161555456cc19ee9b78b89fdd92 | |
parent | 1f32046f8c429752fe6443e0391044697be4bb08 (diff) |
Use Gaussian noise to mess up unit cell
-rw-r--r-- | src/partial_sim.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/partial_sim.c b/src/partial_sim.c index 0fd51eb8..6bf0a2c6 100644 --- a/src/partial_sim.c +++ b/src/partial_sim.c @@ -31,25 +31,20 @@ #include "stream.h" -static int gaussian_noise(double expected, double variance) +static double gaussian_noise(double expected, double variance) { - double x1, x2, w; - double noise; + double x1, x2, noise; - do { + /* A uniformly distributed random number between 0 and 1 */ + x1 = ((double)random()/RAND_MAX); + x2 = ((double)random()/RAND_MAX); - x1 = 2.0 * ((double)random()/RAND_MAX) - 1.0; - x2 = 2.0 * ((double)random()/RAND_MAX) - 1.0; - w = pow(x1, 2.0) + pow(x2, 2.0); + noise = sqrt(-2.0*log(x1)) * cos(2.0*M_PI*x2); - } while ( w >= 1.0 ); - - w = sqrt((-2.0*log(w))/w); - noise = w * x1; - - return expected + noise*sqrt(variance); + return expected + noise*variance; } + static void mess_up_cell(UnitCell *cell) { double ax, ay, az; |