Skip to content

Commit 415167b

Browse files
committedApr 27, 2015
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.
1 parent cd1d625 commit 415167b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

Diff for: ‎src/noise.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ s32 PcgRandom::randNormalDist(s32 min, s32 max, int num_trials)
148148
s32 accum = 0;
149149
for (int i = 0; i != num_trials; i++)
150150
accum += range(min, max);
151-
return ((float)accum / num_trials) + 0.5f;
151+
return round((float)accum / num_trials);
152152
}
153153

154154
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)
Please sign in to comment.