a not so random function...

Hi! :slight_smile:
I’m making a program that randomly picks a led from an array and lights it, then it lights another one, etc… until all lights are lit. It works but they always light in the same order. Can you help me?
Here is my code:
int light;
light = random(pinArray);
digitalWrite(light, HIGH);

One easy way is to use an unconnected analog input pin as a source of random numbers, e.g.:

light = pinArray[analogRead(0) % numberOfPins];

Where numberOfPins is the number of pins in the array. The percent sign (%) means “modulo” or the remainder after division, so 10 % 3 is 1 (because 10 divided by 3 is 3, with 1 left over).

Thank you! Works great! :slight_smile: