fix to prevent random(lo, hi) from returning hi (fixes #4551)

This commit is contained in:
Ben Fry
2016-07-28 19:13:12 -04:00
parent d920b39f4e
commit 762251b257
2 changed files with 9 additions and 1 deletions
+7 -1
View File
@@ -4921,7 +4921,13 @@ public class PApplet implements PConstants {
public final float random(float low, float high) {
if (low >= high) return low;
float diff = high - low;
return random(diff) + low;
float value = 0;
// because of rounding error, can't just add low, otherwise it may hit high
// https://github.com/processing/processing/issues/4551
do {
value = random(diff) + low;
} while (value == high);
return value;
}
+2
View File
@@ -1,6 +1,8 @@
0241 (3.1.2)
X rewrite csv handling
X fix parsing bugs, remove newlines option, improve performance
X prevent random(low, high) from returning 'high'
X https://github.com/processing/processing/issues/4551
gohai
X Fix GLExceptions on Raspberry Pi when using offscreen PGraphics