Hello, I have been trying to let 4 LEDs blink randomly (with a delay I can change with a potentiometer). This works just fine, but I have a question. In this code, there is a change that the "random number generator" generates the same number twice or even three times after one another. If this is the case, a LED blinks twice or three times as long which kills the effect. Is it possible to code that it is impossible for the "random number generator" to generate the same number twice without a different number in between?
If it is unclear: here is an example.
Red blinks once, Green once, but then Blue is chosen twice in a row so it blinks twice as long.
This kills the random blinking effect.
int ranNum;
int pot = A0;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
int snelheid = analogRead(pot);
snelheid = map(snelheid, 0, 1024, 100, 1000);
ranNum=random(2,6);
Serial.println(snelheid);
digitalWrite(ranNum, HIGH);
delay(snelheid);
digitalWrite(ranNum, LOW);
}