Need help with LEDs not working correctly.

I have a problem with my project. It’s supposed to randomize a number and then light up specific LEDs that match it. But it’s only lighting the ones that are coded at the bottom of the code.

int on = HIGH;
int off = LOW;
int led1 = 9;
int led2 = 8;
int led3 = 7;
int led4 = 6;
int led5 = 5;
int led6 = 4;
int led7 = 3;
int button = 2;
int buttonState = 0;
long randNumber = 0;
int numStart = 0;
int numEnd = 1;
int lastButtonState = 0;
int buttonMode = 0;
int Start = 0;
int Stop = 1;


void setup() {
  Serial.begin(9600);
  for (int pinNumber = 3; pinNumber < 10; pinNumber++) {
    pinMode(pinNumber, OUTPUT);
  }
  pinMode(button, INPUT);
  randomSeed(analogRead(0));
}

void loop() {

  buttonState = digitalRead(button);
  if (buttonState == on && numStart != numEnd) {
    Serial.println("Ravistetaan");
    numStart++;
  }
  if (buttonState == on && buttonMode != 1) {
    buttonMode++;
  }
  if (buttonState == on) {
    digitalWrite(led1, on);
    delay(50);
    digitalWrite(led1, off);
    digitalWrite(led2, on);
    delay(50);
    digitalWrite(led2, off);
    digitalWrite(led3, on);
    delay(50);
    digitalWrite(led3, off);
    digitalWrite(led4, on);
    delay(50);
    digitalWrite(led4, off);
    digitalWrite(led5, on);
    delay(50);
    digitalWrite(led5, off);
    digitalWrite(led6, on);
    delay(50);
    digitalWrite(led6, off);
    digitalWrite(led7, on);
    delay(50);
    digitalWrite(led7, off);
    delay(50);


  }


  if (buttonMode == 1 && buttonState == off) {
    buttonMode--;
    Start++;
    numStart--;
    Serial.println("Pyörittää");
    digitalWrite(led7, on);
    delay(50);
    digitalWrite(led7, off);
    digitalWrite(led6, on);
    delay(50);
    digitalWrite(led6, off);
    digitalWrite(led5, on);
    delay(50);
    digitalWrite(led5, off);
    digitalWrite(led4, on);
    delay(50);
    digitalWrite(led4, off);
    digitalWrite(led3, on);
    delay(50);
    digitalWrite(led3, off);
    digitalWrite(led2, on);
    delay(50);
    digitalWrite(led2, off);
    digitalWrite(led1, on);
    delay(50);
    digitalWrite(led1, off);
    delay(1000);
    randNumber = random(1, 7);
    Serial.println(randNumber);
    if (randNumber = 1) {
      digitalWrite(led1, off);
      digitalWrite(led2, off);
      digitalWrite(led3, off);
      digitalWrite(led4, on);
      digitalWrite(led5, off);
      digitalWrite(led6, off);
      digitalWrite(led7, off);
    }
    if (randNumber = 2) {
      digitalWrite(led1, off);
      digitalWrite(led2, off);
      digitalWrite(led3, on);
      digitalWrite(led4, off);
      digitalWrite(led5, on);
      digitalWrite(led6, off);
      digitalWrite(led7, off);
    }
    if (randNumber = 3) {
      digitalWrite(led1, off);
      digitalWrite(led2, off);
      digitalWrite(led3, on);
      digitalWrite(led4, on);
      digitalWrite(led5, on);
      digitalWrite(led6, off);
      digitalWrite(led7, off);
    }
    if (randNumber = 4) {
      digitalWrite(led1, on);
      digitalWrite(led2, off);
      digitalWrite(led3, on);
      digitalWrite(led4, off);
      digitalWrite(led5, on);
      digitalWrite(led6, off);
      digitalWrite(led7, on);
    }
    if (randNumber = 5) {
      digitalWrite(led1, on);
      digitalWrite(led2, off);
      digitalWrite(led3, on);
      digitalWrite(led4, on);
      digitalWrite(led5, on);
      digitalWrite(led6, off);
      digitalWrite(led7, on);
    }
    if (randNumber = 6) {
      digitalWrite(led1, on);
      digitalWrite(led2, on);
      digitalWrite(led3, on);
      digitalWrite(led4, off);
      digitalWrite(led5, on);
      digitalWrite(led6, on);
      digitalWrite(led7, on);
    }
  }


}

So it lights up the LEDs that are coded at the bottom even though the random number it’s assigned to is different. Please help, Thanks.

(deleted)

When you find yourself writing essential the same lines of code over and over it is time to learn about arrays and loops.

That code could be a tiny fraction of the size it is now.

spycatcher2k:

(randNumber = 1)

Oops!

(randNumber == 1)

Same for the other compare lines.

Yeah, that was the problem. Thanks for the quick reply.