Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4073,12 +4073,12 @@ static public void println(Object what) {
* To come...
*
* ( end auto-generated )
* @webref output:text_area
* @param what one-dimensional array
* @usage IDE
* @see PApplet#print(byte)
* @see PApplet#println()
*/
* @webref output:text_area
* @param what one-dimensional array
* @usage IDE
* @see PApplet#print(byte)
* @see PApplet#println()
*/
static public void printArray(Object what) {
if (what == null) {
// special case since this does fuggly things on > 1.1
Expand Down Expand Up @@ -4855,6 +4855,15 @@ static public final double map(double value,

Random internalRandom;

/**
* Sets internalRandom if necessary
*/
protected final void setInternalRandom() {
if (internalRandom == null) {
internalRandom = new Random();
}
}

/**
*
*/
Expand All @@ -4864,9 +4873,7 @@ public final float random(float high) {
return 0;
}

if (internalRandom == null) {
internalRandom = new Random();
}
setInternalRandom();

// for some reason (rounding error?) Math.random() * 3
// can sometimes return '3' (once in ~30 million tries)
Expand Down Expand Up @@ -4896,9 +4903,7 @@ public final float random(float high) {
* @see PApplet#noise(float, float, float)
*/
public final float randomGaussian() {
if (internalRandom == null) {
internalRandom = new Random();
}
setInternalRandom();
return (float) internalRandom.nextGaussian();
}

Expand Down Expand Up @@ -4947,9 +4952,7 @@ public final float random(float low, float high) {
* @see PApplet#noiseSeed(long)
*/
public final void randomSeed(long seed) {
if (internalRandom == null) {
internalRandom = new Random();
}
setInternalRandom();
internalRandom.setSeed(seed);
}

Expand Down Expand Up @@ -4987,6 +4990,15 @@ public final void randomSeed(long seed) {

Random perlinRandom;

/**
* Sets perlinRandom if necessary
*/
protected void setPerlinRandom() {
if (perlinRandom == null) {
perlinRandom = new Random();
}
}


/**
*/
Expand Down Expand Up @@ -5042,9 +5054,7 @@ public float noise(float x, float y) {
*/
public float noise(float x, float y, float z) {
if (perlin == null) {
if (perlinRandom == null) {
perlinRandom = new Random();
}
setPerlinRandom();
perlin = new float[PERLIN_SIZE + 1];
for (int i = 0; i < PERLIN_SIZE + 1; i++) {
perlin[i] = perlinRandom.nextFloat(); //(float)Math.random();
Expand Down Expand Up @@ -5172,7 +5182,7 @@ public void noiseDetail(int lod, float falloff) {
* @see PApplet#randomSeed(long)
*/
public void noiseSeed(long seed) {
if (perlinRandom == null) perlinRandom = new Random();
setPerlinRandom();
perlinRandom.setSeed(seed);
// force table reset after changing the random number seed [0122]
perlin = null;
Expand Down