Help with random numbers

Glad you got your code working!

Something you may want to bear in mind for the future is a general programming principle called D.R.Y which stands for Don't Repeat Yourself. Basically, you take sections of code that are repeated or very similar and turn them into separate functions/classes that can be reused/repurposed.

With that in mind, here's how I might approach this personally:

PS: I've used my own button class KTS_Button.h (3.6 KB) that you're welcome to use, or you can add in your own button code/library.

PPS: If you don't care about printing the pin and LED 'on time' then I've added a slightly shorter lightSequence() function as a comment above in the code.

PPPS: I'm not a huge fan of using delays() as it blocks the rest of the code, but if this is the only code you're running and there isn't any other code to 'block', then it's all good. In your case it will mean that button presses will be ignored while the light/sound sequence is going but I suspect that's what you want anyway.

// Version 0.0

#define NUM_BUTTONS 2
#define NUM_LEDS 4
#define PIEZO_PIN 8

#include "KTS_Button.h"

KTS_Button buttons[NUM_BUTTONS] = { 7, 6 };

int LEDs[NUM_LEDS] = { 9, 10, 11, 12 }; 

// void lightSequence(unsigned long min, unsigned long max) {
//   int pin = random(0, NUM_LEDS);
//   digitalWrite(LEDs[pin], HIGH);
//   delay(random(min, max););
//   digitalWrite(LEDs[pin], LOW);
// }

void lightSequence(unsigned long min, unsigned long max) {
  int pin = random(0, NUM_LEDS);
  unsigned long randTime = random(min, max);

  digitalWrite(LEDs[pin], HIGH);
  delay(randTime);
  digitalWrite(LEDs[pin], LOW);

  Serial.print(F("Pin "));
  Serial.print(pin);
  Serial.print(F(" was on for "));
  Serial.print(randTime);
  Serial.print(F(" millis"));
  Serial.println();
}

void beep(unsigned int freq, unsigned long duration, unsigned long pause) {
  tone(PIEZO_PIN, freq, duration);
  delay(pause);
}

void toneSequence() {
  for (int i = 0; i < 3; i++) {
    beep(100, 500, 1000); // freq, duration, pause
  }
  beep(1000, 200, 3000); // Personally, I think this delay is too long.
}

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < NUM_LEDS; i++)
    pinMode(LEDs[i], OUTPUT);
  randomSeed(analogRead(A0));
}

void loop() {
  for (int i = 0; i < NUM_BUTTONS; i++) {
    if (buttons[i].read() == SINGLE_PRESS) {
      switch(i) {
        case 0:
          delay(2000); // Personally, I think this delay is not neeed.
          toneSequence();
          for (int j = 0; j < 4; j++)
            lightSequence(500, 3000); // Call lightSequence with the min and max delay times
        break;
        
        case 1:
          delay(2000); // Personally, I think this delay is not needed.
          toneSequence();
          for (int j = 0; j < 4; j++)
            lightSequence(50, 7500); // same lightSequence call with new delay min/maxes
        break;
      }
    }
  }
}