How to choose randomly between 3 different specified numbers?

Hi everyone,

I'm trying to write a program to turn an LED ON for 1 sec then turn it off for a time between three choices: off for either 4 secs, 7 secs or 14 secs. I want it to randomly choose between these 3 OFF time values for the whole time the circuit is on.

It's like I'm missing something totally simple so I apologise if it's a stupid question.

Thanks in advance for reading my question and for any help :slight_smile:

:confused:

Read up on the random number generator for the Arduino. Then do something like:

// in setup()
   randomSeed(analogRead(0));

// probably in loop()

   long rand;
   int pause;

   rand = random(1, 4);  // returns a value 1, 2, 3
   switch (rand) {
      case 1:
         pause = 4000;
         break;

     case 2:
         pause = 7000;
         break;


     case 3:
         pause = 14000;
         break;

      default:
         Serial.print("I shouldn't be here, rand = ");
         Serial.println(rand);
         break;
   }
   
   delay(pause);   // There are better alternatives than delay()

// more loop() code??

Awesome. Thanks econjack!

How about

const int pauses[] = {400, 700, 14000);  //global variable

delay(pauses[random(0, 3)]);  //where you want a delay

@Bob: Nice!

econjack:
@Bob: Nice!

Thank you kind sir !