# Easy switching on/off , but hard for newbie!

Hi
Hope someone can help?
I have a 1x relay that I like to use as a switch for a randomly lighting between 2 incandescent lights, when one is lit the other is out, and vice versa. I have gotten the lights to work through the relay but I cant understand the random and randomSeed states…
I want to set a min and max seconds time delay that the lights will be lit and the relay switches between the 2 lights.
Hope I make sense?
And hope that someone could help me with some sketch that works cause I dont understand and my brain is muchy now
Regards
Per

You mus use, like you said, the `random()` function. This function, don't gives you a really random number (almost random), and to start working it need the `randomSeed()`, to start he process of generating the "random" numbers. To make the `random()` function to generate a little more random numbers you need to seed it with a random number. For that you can use a analog input when it's not connected to anything (and then it picks noise, that is random).

The technical explanation without many technical details is this. To do the code, you can start with the example of the page:

perolalars:
Hi
(...)I want to set a min and max seconds time delay that the lights will be lit and the relay switches between the 2 lights.
Hope I make sense?
(...)

To do this, you can use the `map()` function, or you can use `random(min, max)`

So, you can do something like this:

``````const int relayPin = 13;

long randNumber;

int min = 1000;
int max = 1500;

boolean state=false;

void setup(){
Serial.begin(9600);
pinMode(relayPin, OUTPUT);

}

void loop() {
randNumber = random(min, max);
Serial.println(randNumber);

if (state == false) {
state = true;
digitalWrite(relayPin, HIGH);
}
else {
state = false;
digitalWrite(relayPin, LOW);
}

delay (randNumber);
}
``````

NOTE: I didn't try it.

Hi luisilva and thanks for reply.
It works great and now I have a base for further tuning!
I had read the http://arduino.cc/en/Reference/Random but did not understand how to use it
Now I do, thank you so much!
Best regards
Per