I need with a button that generates a random number.

I need help trying to make this project. Currently I’m looking to make the button generate a random number between 1-6 when the button is released. here is the code: int off = LOW;
int on = HIGH;
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;
int numStart = 0;
int numEnd = 1;
int lastButtonState = 0;

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){
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);
randNumber = random(7);
delay(100);
Serial.println(randNumber);
}
else{

digitalWrite(led1, off);
digitalWrite(led2, off);
digitalWrite(led3, off);
digitalWrite(led4, off);
digitalWrite(led5, off);
digitalWrite(led6, off);
digitalWrite(led7, off);
}
}

The usual question. How is the input wired ? Is there a pulldown resistor in place or it floating in the breeze at an unknown voltage ?

Try this. No external pullup or pulldown resistor needed

const byte inPin = A4;

void setup()
{
  Serial.begin(115200);
  pinMode(inPin, INPUT_PULLUP);
}

void loop()
{
  while (digitalRead(inPin) == HIGH)
  {}
  Serial.println(random(7));
}

Is there a problem? If so please state this.

While doing so, also please read the sticky which also explains how you can properly post your code.

Just_Joe:
I need help trying to make this project. Currently I’m looking to make the button generate a random number between 1-6 when the button is released.

From the code it looks like there are two things wrong:
The button generates a random number when it is PRESSED, not RELEASED.
The random number is in the range 0 to 6 and not 1 to 6.
To fix both of those, change:

    randNumber = random(7);
    delay(100);
    Serial.println(randNumber);
  }
  else
  {

to

    delay(100);
  }
  else
  {
    // Button released
    randNumber = random(1, 7);
    Serial.println(randNumber);