Blinking LEDs for a set number of times followed by another action

halfnote:
Ok, I think I'm getting a bit closer but am not sure if this is the best way of going about it. In fact, I'm sure there must be a better way. Here is the combined code:

int pin2 = 2;

int pin3 = 3;
int pin4 = 4;

long timestamp = 0;  // long is a much larger integer
boolean ledState = LOW;   
int delayLength = 500; // how long between intervals

int ranNum;
int ranDel;

int maxnum = 1; //Blink random LED 1 time
int count = 0; //Blink counter

void setup() {
 
  randomSeed(analogRead(0)); 
   
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
   
  Serial.begin(9600);
 
}

void loop() {

// make all 3 LEDs flash 3x
  if ( (millis() - timestamp > delayLength) && (timestamp < 2506) ) {
    // half a second has passed and timestampe is less than 2506, do:
    ledState = !ledState; // toggles the ledState between true/false
    digitalWrite(pin2, ledState); // make the led change
    digitalWrite(pin3, ledState);
    digitalWrite(pin4, ledState);
    timestamp = millis();
    Serial.println(timestamp);
  }
 
    //light up one LED at random for 4 seconds
  if ( (timestamp > 2510) && (count < maxnum) ) {
  ranNum=random(2,5);
  digitalWrite(ranNum, HIGH);
  delay(4000);
  digitalWrite(ranNum, LOW);
  delay(2000);
  Serial.println(count);
 
  count++; //increments count making if statement false
  }
 
}




When I run this code, it flashes all 3 LEDs 3x and then turns off 2 of them at random leaving 1 random LED on. This more or less achieves what I want; however, I'd prefer that 1 random LED turn ON rather than 2 random LEDs turning off. The other, more significant problem, is that I don't know how to now loop this. As it stands, it runs once and then stops altogether because I've based my if() statements on timestamps and I'm not sure that timestamps can be reset. 

And while I don't want to get too ahead of myself, I have to keep in mind that I also have to be able to use a slide potentiometer on a completely different set of LEDs and have these LEDs react to the pot in real time.

you're making great progress :).

a next suggestion: how about just using timestamps for timing your led action, and not for also seeing what you have to do? it right now makes your timestamps pretty complicated to keep track of.
make a second variable, named state. state 0 = for example could mean that you're blinking your leds. After the leds have blinked 3 times, have the code blinking the leds put the state to 1. state 1 is selecting a random led and lighting it for a certain amount of time. After this time has expired, the lighting a random led could can put the state back to 0. and you'll loop nicely trough the 2 behaviors.

If you then want to expand this with more actions, you can just add more states. If multiple actions need to happen together, you can have multiple pieces of code share the same state (so when state = 0, both the flashing of the leds is triggered, but also the reading of the potentiometer).

it is possible to make everything timing based, and keep track of all information in 1 variable, but it makes everything a lot more complicated, and unless you're making a huge sketch and need every byte you can get, you're just making it hard for yourself :).

And as bulldog already set, why 2 leds are turning off, rather than 1 turning on, is becasue after turning off all 3 leds, your code doesn't wait before turning 1 on again. so you won't be able to see it turning off those 3 leds, it's just way too fast :).

good luck :).