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.
This commit is contained in:
kwolekr 2015-04-27 04:05:25 -04:00
parent cd1d625ab2
commit 415167b228

@ -148,7 +148,7 @@ s32 PcgRandom::randNormalDist(s32 min, s32 max, int num_trials)
s32 accum = 0; s32 accum = 0;
for (int i = 0; i != num_trials; i++) for (int i = 0; i != num_trials; i++)
accum += range(min, max); accum += range(min, max);
return ((float)accum / num_trials) + 0.5f; return round((float)accum / num_trials);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////