projects
/
oweals
/
minetest.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
cd1d625
)
Noise: Fix PcgRandom::randNormalDist() when range contains negative numbers
author
kwolekr
<kwolekr@minetest.net>
Mon, 27 Apr 2015 08:05:25 +0000
(
04:05
-0400)
committer
kwolekr
<kwolekr@minetest.net>
Mon, 27 Apr 2015 08:05:25 +0000
(
04:05
-0400)
This fixes an issue with erroneous float-to-int rounding that resulted in
truncation toward 0, causing a biased distribution.
src/noise.cpp
patch
|
blob
|
history
diff --git
a/src/noise.cpp
b/src/noise.cpp
index 2e4588124213be8566cff2b1abb095b689646607..614234aa4c52bbf9370fe86f85ecf4f63be3eff1 100644
(file)
--- 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)
;
}
///////////////////////////////////////////////////////////////////////////////