aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/utils.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2014-10-24 15:56:13 +0200
committerThomas White <taw@physics.org>2014-10-24 15:56:13 +0200
commit1351a057519622ba2b5ee8ccf6397bd62381eeec (patch)
tree5c9fbe0b1beb96d0ef56c19205d42e014391dd06 /libcrystfel/src/utils.c
parentdf7f5d098196ae4d67aaf89d626682a26062caa0 (diff)
Avoid log(0) in gaussian_noise()
Diffstat (limited to 'libcrystfel/src/utils.c')
-rw-r--r--libcrystfel/src/utils.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libcrystfel/src/utils.c b/libcrystfel/src/utils.c
index e09b53c3..f8f93046 100644
--- a/libcrystfel/src/utils.c
+++ b/libcrystfel/src/utils.c
@@ -186,9 +186,10 @@ double gaussian_noise(gsl_rng *rng, double expected, double stddev)
{
double x1, x2, noise;
- /* A uniformly distributed random number between 0 and 1 */
- x1 = gsl_rng_uniform(rng);
- x2 = gsl_rng_uniform(rng);
+ /* Generate two uniformly distributed random numbers between 0 and 1,
+ * including 1 but not 0. */
+ x1 = 1.0 - gsl_rng_uniform(rng);
+ x2 = 1.0 - gsl_rng_uniform(rng);
noise = sqrt(-2.0*log(x1)) * cos(2.0*M_PI*x2);