From: kwolekr Date: Mon, 27 Apr 2015 08:05:25 +0000 (-0400) Subject: Noise: Fix PcgRandom::randNormalDist() when range contains negative numbers X-Git-Tag: 0.4.13~326 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=415167b228dea8b4108d7fe164c7fec8c061dcf5;p=oweals%2Fminetest.git 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. --- 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); } ///////////////////////////////////////////////////////////////////////////////