We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm wondering why noise(0) will give me the same value everytime when I run my sketch. But it doesn't as soon as I run it again. Meaning, noise function must be storing my values somewhere. Is that true?
My tessting code is:
float x;
float y;
void setup() {
size(800,600);
fill(255);
noStroke();
getRandom();
}
void draw() {
background(240,168,128);
ellipse(x, y, 20, 20);
}
void mouseClicked() {
getRandom();
println(x, y);
}
void getRandom() {
x = noise(0) *200 + width/2;
y = noise(0) *200 + height/2;
}
So, first time i run the sketh I get, let's say:
(565.2674, 465.2674)
And even clicking on screen the value stays the same. But as soon as I run the sketch again I get something else, like:
(494.57538, 394.57538)
Why is so?
Answers
https://Processing.org/reference/noiseSeed_.html
Great, thanks. Then yes, the noise function stores a "seed".
What about all the rest of the numbers? The depends directly on the seed? So, same number will always return same result, right?
My test:
float x;
float y;
Returns:
I'll assume yes, all the variations are coupled to seed.
Yes, the "seed" is a number being given to a pseudo-random number generator (PNRG). When given a seed the sequence of numbers it produces thereafter is deterministic -- same seed, same sequence.
To learn more see:
https://en.m.wikipedia.org/wiki/Pseudorandom_number_generator
...and read the collection of entries under the Random section of the Processing Reference:
https://processing.org/reference/
Great. Thanks both. Also I found these crazy videos useful: