How to random chose a variabele with array?

Hello,

I want to let the Arduino choose complete random a variabele. I mean, I declared the variabele LED[] from 1 - 19. How can I let choose the Arduino a random array from the list? I tried with: random (LED[1] , LED[19]) but it doesn't work

Here is a link to my code: http://www.modeltreinen.comze.com/Arduino/ModuleDecoderV1_5_DCC_4.ino

regards, minitreintje

random takes values that you want a random number constrained to.

You will have to check the reference, but I think the high value is not inclusive ( so add one ), but check anyway.

LED[ random( 0, 19 ) ];

If you want to select an entry from the array at random, you need to generate a random number in the range 0 … 19 and use that to select the array entry.

int entry = random(0, 20);
int selectedLed = LED[entry];

Note that if you declare LED[20] the valid index values are in the range 0 … 19. Random(0,20) returns a value in the range 0 … 19.

Also note that unless you apply a random seed value, the value returned by random() is not actually random.

Thank you for the fast reply. I will try it now. It works! THANK YOU :p

regards, minitreintje