I have tried to figure out how I can choose randomly between 2 LEDs - but it ALLWAYS lights up the same LED after turning ON or after Reset !
I've seen a lot of code samples - nothing works right - here are a sample:
int relay = random(0,1);
but relay is ALLWAYS 0 - WHY ?
How can this be done ?
Check the documentation for "random"
Please show a sketch.
Use all the analog inputs.
You can also use the signature bytes, to have a difference between Arduino boards.
You can store a random to EEPROM, so next time you start with a different value.
I tried something here: Generating random number from function pre setup - #5 by Koepel (ignore that part that it is used before setup, the function should be called in setup).
It seems to be not right as you can read in the last posts of that topic, but I still don't know why
By the way, you should also fix the bug. When you do
random(0,1) then a 0 is returned. Always. Every time. Read the reference: random() - Arduino Reference (pay attention to the word "exclusive").
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.