summaryrefslogtreecommitdiff
path: root/src/noise.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-04-27 04:05:25 -0400
committerkwolekr <kwolekr@minetest.net>2015-04-27 04:05:25 -0400
commit415167b228dea8b4108d7fe164c7fec8c061dcf5 (patch)
tree47f147beffc37d4d08c341f50825ce9edc1e6b17 /src/noise.cpp
parentcd1d625ab21e741e91be7d2190bb4fd59fab3200 (diff)
downloadminetest-415167b228dea8b4108d7fe164c7fec8c061dcf5.tar.gz
minetest-415167b228dea8b4108d7fe164c7fec8c061dcf5.tar.bz2
minetest-415167b228dea8b4108d7fe164c7fec8c061dcf5.zip
Noise: Fix PcgRandom::randNormalDist() when range contains negative numbers
This fixes an issue with erroneous float-to-int rounding that resulted in truncation toward 0, causing a biased distribution.
Diffstat (limited to 'src/noise.cpp')
-rw-r--r--src/noise.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/noise.cpp b/src/noise.cpp
index 2e4588124..614234aa4 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -148,7 +148,7 @@ s32 PcgRandom::randNormalDist(s32 min, s32 max, int num_trials)
s32 accum = 0;
for (int i = 0; i != num_trials; i++)
accum += range(min, max);
- return ((float)accum / num_trials) + 0.5f;
+ return round((float)accum / num_trials);
}
///////////////////////////////////////////////////////////////////////////////