[SOLVED] Random LED's

Mubanga:
Thanks John! Although this way I won't be able to use shift registers won't I? because in my final project I will be using 27 LED's. But that's not to big of a problem, in that case I will use I2C I/O expanders.

You can use an unsigned long (32-bit integer) to keep track of which LEDs you want on and off.

int timer = 1000; //Sets timer
const int pinCount = 6; //Sets the number of pins
int Number = 3; //Sets the amount of LEDs that will go on
unsigned long pattern;
int thisPin;
int alreadySet;

void loop(){
  // Turn off all the LEDs
  pattern = 0;

  // Turn on "Number" randonm LEDs
  for (int i=0; i<Number; i++) {
    do {
      thisPin = random(pinCount);
      alreadySet = pattern & (1<<thisPin));
      pattern |= (1<<thisPin);
    } 
    while (alreadySet);  // If the LED was already on, try a different one
  }
  //  Send 'pattern' to shift registers
  delay(timer);
}

[/quote]