Random not working

I have an issue. I throw this onto my Arduino Mega(with a joystick shield and a piezo buzzer attached) and the code is supposed to spit out a random number between 1 and 4.
But it isn't random. When I do it, it repeats, each time.

here is the code:

#include <LiquidCrystal_I2C.h>
#include <JoystickShield.h> // include JoystickShield Library
#include <TrueRandom.h>
JoystickShield joystickShield; // create an instance of JoystickShield object
const int buzzer = 11;
boolean isAny = false;
double t;
int score = 0;
int randomNumber;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
  randomSeed(analogRead(0));
    Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
   lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(1,0);
  lcd.print("Block It");
  lcd.setCursor(0,1);
  lcd.print("Press F to start");
    delay(100);
    // new calibration function
    joystickShield.calibrateJoystick();
    joystickShield.processEvents();
    while(!joystickShield.isFButton()){
      joystickShield.processEvents();
    }
    tone(buzzer, 1750, 500);
    delay(750);
    tone(buzzer, 1750, 500);
    delay(750);
    tone(buzzer, 1750, 500);
    delay(750);
    tone(buzzer, 2500, 500);
    delay(150);
}

void loop() {
  Serial.print("We made it");
  lcd.clear();
  lcd.setCursor(0, 8);
  lcd.print(score);
  if(score > 249){
    lose();
    Serial.print("YOU SUCK");
    while(true){}
  }
  delay(500); // process events
  gameManage();

}
void gameManage(){
  randomNumber = round(random(1000,5000)/1000);
  delay(100);
  Serial.println(randomNumber);
  Serial.println();
  delay(100);
  
  switch(randomNumber){
  case 1: upIt();
  case 2: leftIt();
  case 3: downIt();
  case 4: rightIt();
  }
}
void upIt(){
  lcd.setCursor(0,9);
  lcd.print("Up It");
  Serial.print("BEEP");
  tone(buzzer, 1000, 100);
  Serial.print("beeped");
  delay(100);
  int d = 0;
  boolean pressed = false;
  while(d < 200 - (score * 3) && !pressed){
    Serial.print("waiting");
  delay(1);
  d++;
  joystickShield.processEvents();
  if(joystickShield.isUpButton()) {
    pressed = true;
    tone(buzzer, 1000, 100);
    delay(100);
  }}
  if(!pressed){
    lose();
    while(true){}}
  score++;
}

void leftIt(){
  lcd.setCursor(0,9);
  lcd.print("Up It");
  Serial.print("BEEP");
  tone(buzzer, 1500, 100);
  Serial.print("beeped");
  delay(100);
  int d = 0;
  boolean pressed = false;
  while(d < 200 - (score * 3) && !pressed){
    Serial.print("waiting");
  delay(1);
  d++;
  joystickShield.processEvents();
  if(joystickShield.isLeftButton()) {
    pressed = true;
    tone(buzzer, 1500, 100);
    delay(100);
  }}
  if(!pressed){
    lose();
    while(true){}}
  score++;
}
void downIt(){
  lcd.setCursor(0,9);
  lcd.print("Up It");
  Serial.print("BEEP");
  tone(buzzer, 2000, 100);
  Serial.print("beeped");
  delay(100);
  int d = 0;
  boolean pressed = false;
  while(d < 200 - (score * 3) && !pressed){
    Serial.print("waiting");
  delay(1);
  d++;
  joystickShield.processEvents();
  if(joystickShield.isDownButton()) {
    pressed = true;
    tone(buzzer, 2000, 100);
    delay(100);
  }}
  if(!pressed){
    lose();
    while(true){}}
  score++;
}
void rightIt(){
  lcd.setCursor(0,9);
  lcd.print("Up It");
  Serial.print("BEEP");
  tone(buzzer, 2500, 100);
  Serial.print("beeped");
  delay(100);
  int d = 0;
  boolean pressed = false;
  while(d < 200 - (score * 3) && !pressed){
    Serial.print("waiting");
  delay(1);
  d++;
  joystickShield.processEvents();
  if(joystickShield.isRightButton()) {
    pressed = true;
    tone(buzzer, 2500, 100);
    delay(100);
  }}
  if(!pressed){
    lose();
    while(true){}}
  score++;
}
void lose(){
  lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("You lose");
    lcd.setCursor(0,1);
    lcd.print("Score: ");
    lcd.setCursor(0,9);
    lcd.print(score);
    tone(buzzer, 1500, 1000);
    delay(1000);
    tone(buzzer, 1250, 1000);
    delay(1000);
    tone(buzzer, 1000, 2000);
}

That is the intended behavior of a pseudo random number generator. Use the randomSeed() function to start the sequence at a new place.

That should introduce a sort of random starting point for the random number generator (Arduino random() function) if the analog input is floating (not connected to anything).

Is the A0 input unconnected? Edit, I just checked the JoystickShield.cpp file and the joystick defaults to using A0 and A1 for the joystick. So the seed may not be very random. Try putting a different and floating analog input in the randomSeed() function.

You include the TrueRandom library, but do not use the functions thereof. Why not?

@groundFungus I tried to implement the true random, but i would get weird pauses whenever it tried to get a random number. and it still didn't change. TY for the advice

I also tried using the A2 port, still no dice.

@jremington I do. It updates every time too.

Why do you need to round that? The random() function returns a long data type which is an integer. What does rounding do for an integer number?

Why not just
random(1, 5);

That should work unless that pin is also connected to something.

I got nothin' else.

Because I was reading another post along the same line of issues, and it suggested that.

And I need to round it because if it returns 4500, and I divide that by 1000, I would get 4.5

Your good, ty for your help

Yeah, I just realized that. Sorry, I apologize. It must be time for my nap.

Maybe my board has an issue.
Ill try my arduino uno, and see if that makes a change.

Connect your DMM to the A2 input (or input of interest) and ground to watch the voltage. The reading should bounce around if the input is floating.

what is a dmm? :joy:
sorry im blonde

same issue on an arduino uno

Digital MultiMeter. One of the main tools that one must have to pursue the electronics hobby. It need not be expensive. You can get a decent basic one for under $30.00 US. It should measure voltage and current, DC and AC, and resistance.

Alright. I prob can get one. I will also try adding a long wire to it to add more variation

I tried, and all show about 4.8 volts. Consistently.
I'm going to dig through my joystick/shield Library, and try and see if it initiates them somehow.

This is not a good method of initializing randomSeed() to a different number each time. Use the microsecond() timing of a button press, or something that is more reliably random.

Experiment by starting randomSeed() with different numbers that YOU choose, and you will see that it does what it is supposed to do.

alr ty