We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, i'm trying to control a randomSeed() parameter with a slider to create a random number that i can use again in a running sketch, i'm having problems to change the randomSeed, it always get stucked, if i comment the line 31( "sliderValue= int(random(10));") it runs ok, but of course i don't have the random, here's the sketch:
import controlP5.*;
ControlP5 cp5;
//int sliderValue;
int caos, sliderValue;
color myColor;
void setup() {
size(700, 400);
noStroke();
cp5 = new ControlP5(this);
cp5.addSlider("sliderValue")
.setPosition(100, 50)
.setRange(0, 10)
.setNumberOfTickMarks(10)
;
cp5.addSlider("caos")
.setPosition(100, 100)
.setRange(0, 10)
.setNumberOfTickMarks(10)
;
}
void draw() {
background(0);
randomSeed(caos);
sliderValue= int(random(10));
fill(map(sliderValue, 0, 10, 0, 255));
rect(0, 0, width, 100);
println("SLIDER VALUE", sliderValue);
println("CAOS", caos);
}
void slider(float theColor) {
myColor = color(theColor);
println("a slider event. setting background to "+theColor);
}
Answers
According to randomSeed()'s reference:
https://Processing.org/reference/randomSeed_.html
It resets random() back to a pre-determined sequence of pseudo-random values.
You should execute randomSeed() when the slider's value is changed rather than each single draw().
Hi, thanks for your answer, i've tryied that, maybe i'm missing something, here's the code:
I said you should only change randomSeed() when the "seed" actually changes.
I didn't mention anything about not using random() itself! :-<
I thought the seed was only good to repeat a serie of pseudo-random each time the program runs. How this works during runtime?
from reference: