mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
add randomGaussian()
This commit is contained in:
@@ -5078,25 +5078,34 @@ public class PApplet extends Applet
|
||||
*
|
||||
*/
|
||||
public final float random(float high) {
|
||||
// avoid an infinite loop when 0 or NaN are passed in
|
||||
if (high == 0 || high != high) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (internalRandom == null) {
|
||||
internalRandom = new Random();
|
||||
}
|
||||
|
||||
// for some reason (rounding error?) Math.random() * 3
|
||||
// can sometimes return '3' (once in ~30 million tries)
|
||||
// so a check was added to avoid the inclusion of 'howbig'
|
||||
|
||||
// avoid an infinite loop
|
||||
if (high == 0) return 0;
|
||||
|
||||
// internal random number object
|
||||
if (internalRandom == null) internalRandom = new Random();
|
||||
|
||||
float value = 0;
|
||||
do {
|
||||
//value = (float)Math.random() * howbig;
|
||||
value = internalRandom.nextFloat() * high;
|
||||
} while (value == high);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public final float randomGaussian() {
|
||||
if (internalRandom == null) {
|
||||
internalRandom = new Random();
|
||||
}
|
||||
return (float) internalRandom.nextGaussian();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from random.xml )
|
||||
*
|
||||
@@ -5124,6 +5133,7 @@ public class PApplet extends Applet
|
||||
return random(diff) + low;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from randomSeed.xml )
|
||||
*
|
||||
@@ -5140,8 +5150,9 @@ public class PApplet extends Applet
|
||||
* @see PApplet#noiseSeed(long)
|
||||
*/
|
||||
public final void randomSeed(long seed) {
|
||||
// internal random number object
|
||||
if (internalRandom == null) internalRandom = new Random();
|
||||
if (internalRandom == null) {
|
||||
internalRandom = new Random();
|
||||
}
|
||||
internalRandom.setSeed(seed);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user