How to exclude the previos number from random() function?

Hello!
I'm an Arduino beginner. In one of my projects, I have got 3 LEDs. I want to turn on just one of them chosen by the random() function. The next time that random() makes his choice, I want to exclude the previous number extracted. How can I do it?
Thanks in Advance.

Francesco

A simple while loop - check if the value returned is the same as the last.
If it is, pick a new one.

Or in constant time, a random number between 1 and N, excluding some other number M...

X = random number between 1 and N-1
if (X >= M) X++;

or number = (number + random(1, nr_entries)) % nr_entries;That way the old number is automatically excluded. nr_entries = 3 (as in your case) random returns a 1 or a 2, the modulo of the addition will return a new value.

A simple while loop - check if the value returned is the same as the last.
If it is, pick a new one

That is trial and error, i am so disappointed :o

Hi!
I understood what you've said... but I don't know how to put it in my code! Sorry, but, as I said before, I'm starting now to use Arduino.

I have something similar to this:

digitalWrite(random(10, 13), HIGH);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);

Imagine it to be looped (obviously, the LEDs are connected to pins 10, 11, 12).
Would you give me some examples?
Thank you!

Francesco

const uint8_t nr_pins = 3;
const int ledpin[] = {5, 6, 7};  // you have to store the pin nrs in an array

void setup() {
  for (uint8_t i = 0; i < nr_pins; i++) { // set them all to ouput
    pinMode(ledpin[i], OUTPUT);
  }
}

void loop() {
  static uint8_t pin = random(nr_pins); // initial can be anything, as example say it '1'
  for (uint8_t i = 0; i < nr_pins; i++) {
    if (i == pin) digitalWrite(ledpin[i], HIGH);  // set one of the pins HIGH
    else digitalWrite(ledpin[i], LOW);  // and the others LOW
  }
  delay(1000);
  pin = (pin + random(1, nr_pins)) % nr_pins; // if pin is '1' say the random = '2' together = '3'
                                            // and 3 % 3 = 0
}

Something like this. please remember to post code within </> code-tags