On Power up the outputs go Crazy for a few seconds HELP

Im using an arduino mega inside my truck to control everything extra i do. It has wires leading back to 16 relays in the bed of my truck. Its similar to the “Jeeputer” on youtube. my problem is when i start my truck for a few seconds after all the relays (outputs) go crazy and will not stay low like i need. I’m not sure what to do. I had to delete the bulk of the code because i exceeded the character limit but i left the startup (where the problem seems to be) and the loop that sets the outputs during operation
My only guess thus far is that it could be dirty power

#define Pgup 30     // page up
#define Pgdwn 31    // page down
#define Lus 32     // select left side top
#define Lls 33     // left lower select
#define Rus 34     // right side upper select
#define Rls 35     // right side lower select 
#define Batt1 A0    // batt 1 read pin
#define Battery A1    //batt 2 read pin
#define Backlight 2  // backlight led
#define lightsensor A7 // the pin we read the light level from


/*

 
 
 large relays     cable # 2       
 backuplights      relay 1 pin 44 
 offroadlights     relay 2 pin 45
 relay 3 pin 46
 relay 4 pin 47
 relay 5 pin 48
 relay 6 pin 49
 relay 7 pin 50
 relay 8 pin 51
 
 
 small relays            
 cablights    relay 1 pin 36
 bedlights    relay 2 pin 37
 beatleds     relay 3 pin 38
 relay 4 pin 39
 relay 5 pin 40
 relay 6 pin 41
 relay 7 pin 42
 battery isolator   relay 8 pin 43
 
 
 */


byte p20[8] = {
  B11111,
  B11110,
  B11100,
  B11100,
  B11000,
  B10000,
  B10000,
};

byte p21[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};





unsigned int timesince = 0; // used to see the last time we reset
byte timemax = 0; // max time its been on    // eeprom 20
unsigned long timebutton = 0; // debounce for the buttons that lets the program keep going 
boolean ranonce = false;   // used to tell if we ran through the entire program one time
boolean settings = false;  // used to tell if we are in the settings 
boolean lightchange = false; // used to tell if the light has changed basically did the running lights come on or go off when false it changed
byte pgup = 1;
byte pgdwn = 1;
byte lus = 1;
byte lls = 1;
byte rus = 1;
byte rls = 1;        //ints to hold the button values
byte page = 1;    // starting page nuumber
int batt11 = 0; // stores the first battery reading 0-1023 on battery 1
int batt22 = 0; // stored the first battery reading 0-1023 on battery 2
float batt1 = 0;    // battery voltages         USE LCD.PRINT(VARIABLE,4)      THE 4 IS HOW MANY DECIMALS YOU WANT TO DISPLAY
float battery = 0;    // battery voltages 
float dualb = 13.00; // the voltage we will connect the second battery
float lowb = 12.00;  // considered too low will not connect if battery 2 is below this
byte backlevel = 0;  // stored in eeprom adjustable in settings used for day brightness
byte backlevelnight = 0; // stored in eeprom adjustable in settings used for the night brightness
boolean once = false; //if this is false everything on the disply will update, keeps it from constantly updating everything
byte time = 0;  // debounce time set from the eeprom and program 
byte offroadlights = 0;
byte backuplights = 0;
byte cablights = 0;  // |
byte cablights1 = 0; // | only because it has an auto function used to tell if its on or off 
byte bedlights = 0;
byte beatleds = 0;
boolean batteryisolator = false; // when true both batteries connected 
byte batterys = 0; // 0= auto 1 = off 2 = on 
boolean night = false;   // when true we use the night time brightness number 
#include <EEPROM.h>
//#include <Wire.h>
#include <LiquidCrystal.h>   //pins 50, 51, 52, 53  is spi for programming dont use
LiquidCrystal lcd(22,23,24,25,26,27);  //rs/en/d4/d5/d6/d7  //pins for lcd on mega 






void setup() {
  
    digitalWrite(36, LOW);
  digitalWrite(37, LOW);
  digitalWrite(38, LOW);
  digitalWrite(39, LOW);
  digitalWrite(40, LOW);
  digitalWrite(41, LOW);
  digitalWrite(42, LOW);
  digitalWrite(43, LOW);

  digitalWrite(44, LOW);
  digitalWrite(45, LOW);
  digitalWrite(46, LOW);
  digitalWrite(47, LOW);
  digitalWrite(48, LOW);
  digitalWrite(49, LOW);
  digitalWrite(50, LOW);
  digitalWrite(51, LOW);
  
  pinMode(36, OUTPUT);
  pinMode(37, OUTPUT);
  pinMode(38, OUTPUT);
  pinMode(39, OUTPUT);
  pinMode(40, OUTPUT);
  pinMode(41, OUTPUT);
  pinMode(42, OUTPUT);
  pinMode(43, OUTPUT);
  pinMode(44, OUTPUT);
  pinMode(45, OUTPUT);
  pinMode(46, OUTPUT);
  pinMode(47, OUTPUT);
  pinMode(48, OUTPUT);
  pinMode(49, OUTPUT);
  pinMode(50, OUTPUT);
  pinMode(51, OUTPUT);
  
  digitalWrite(36, LOW);
  digitalWrite(37, LOW);
  digitalWrite(38, LOW);
  digitalWrite(39, LOW);
  digitalWrite(40, LOW);
  digitalWrite(41, LOW);
  digitalWrite(42, LOW);
  digitalWrite(43, LOW);

  digitalWrite(44, LOW);
  digitalWrite(45, LOW);
  digitalWrite(46, LOW);
  digitalWrite(47, LOW);
  digitalWrite(48, LOW);
  digitalWrite(49, LOW);
  digitalWrite(50, LOW);
  digitalWrite(51, LOW);

  pinMode(13, OUTPUT); // onboard led
  pinMode(pgup, INPUT);
  pinMode(pgdwn, INPUT);
  pinMode(lls, INPUT);
  pinMode(lus, INPUT);
  pinMode(rus, INPUT);
  pinMode(rls, INPUT);
  backlevel = EEPROM.read(1);         //
  backlevelnight = EEPROM.read(2);   //
  time = EEPROM.read(3);             //  bring in the stored variables 
  cablights = EEPROM.read(4);       //
  timemax = EEPROM.read(20);        //
  analogWrite(Backlight, 255);
  //Wire.begin();   
  lcd.begin(20,4);
  lcd.print("     Jonathan's     ");  
  lcd.setCursor(0,1);           
  lcd.print("       ForUter     ");     // " without being comented out causes stack overflow error 
  lcd.setCursor(0,2);
  lcd.print("    Arduino Mega    ");
  lcd.setCursor(0,3);
  lcd.print("   Under The Hood   ");
  delay(2000);
  lcd.clear();
  //clear lcd
  Serial.begin(9600);
  lcd.createChar(9, p20);
  lcd.createChar(10, p21);
}


void loop() {
  millis(); // our timer 
  
  
  if(ranonce == false) {
   
  digitalWrite(36, LOW);
  digitalWrite(37, LOW);
  digitalWrite(38, LOW);
  digitalWrite(39, LOW);
  digitalWrite(40, LOW);
  digitalWrite(41, LOW);
  digitalWrite(42, LOW);
  digitalWrite(43, LOW);

  digitalWrite(44, LOW);
  digitalWrite(45, LOW);
  digitalWrite(46, LOW);
  digitalWrite(47, LOW);
  digitalWrite(48, LOW);
  digitalWrite(49, LOW);
  digitalWrite(50, LOW);
  digitalWrite(51, LOW); 
    
  }
  
  
  
  

  timesince = millis()/60000; // time since reset in minutes
  if(timesince > timemax) {
    timemax = timesince;
    timemax = constrain(timemax, 0, 255); // maximum minutes on constrained to 255 for eeprom
    EEPROM.write(20, timemax); 
  }
  //digitalWrite(13, HIGH);   // shows action
  //delay(5);
  //digitalWrite(13, LOW);
  if(night == false && lightchange == false) {  // go into day mode
    lightchange = true;
    analogWrite(Backlight, backlevel);
    if(cablights == 2 && cablights1 != 0) {
      cablights1 = 0;
      Shift();
    }
  } 
  else if(night == true && lightchange == false) {  // go into night mode 
    lightchange = true;
    analogWrite(Backlight, backlevelnight);
    if(cablights == 2 && cablights1 != 1) {
      cablights1 = 1;
      Shift();
    }
  }




void Shift() {
  if(cablights1 == 1) {
    digitalWrite(36, HIGH); 
  } 
  else {
    digitalWrite(36, LOW); 
  }
  if(bedlights == 1) {
    digitalWrite(37, HIGH); 
  } 
  else {
    digitalWrite(37, LOW); 
  }
  if(beatleds == 1) {
    digitalWrite(38, HIGH); 
  } 
  else {
    digitalWrite(38, LOW); 
  }
 if(batteryisolator == true) {
   digitalWrite(43, HIGH);
 } if(batteryisolator == false) {
  digitalWrite(43, LOW); 
 }






  if(backuplights == 1) {
    digitalWrite(44, HIGH); 
  } 
  else {
    digitalWrite(44, LOW); 
  }
  if(offroadlights == 1) {
    digitalWrite(45, HIGH); 
  } 
  else {
    digitalWrite(45, LOW); 
  }




    //digitalWrite(36, LOW);
  //digitalWrite(37, LOW);
  //digitalWrite(38, LOW);
  digitalWrite(39, LOW);
  digitalWrite(40, LOW);
  digitalWrite(41, LOW);
  digitalWrite(42, LOW);
  //digitalWrite(43, LOW);

  //digitalWrite(44, LOW);
  //digitalWrite(45, LOW);
  digitalWrite(46, LOW);
  digitalWrite(47, LOW);
  digitalWrite(48, LOW);
  digitalWrite(49, LOW);
  digitalWrite(50, LOW);
  digitalWrite(51, LOW);

}
void setup() {
  
    digitalWrite(36, LOW);
  digitalWrite(37, LOW);
  digitalWrite(38, LOW);
  digitalWrite(39, LOW);
  digitalWrite(40, LOW);
  digitalWrite(41, LOW);
  digitalWrite(42, LOW);
  digitalWrite(43, LOW);

It is more usual to set pinMode before writing to a pin.

usually I do. I heard that might be one way to get it to stay but it didnt work. just put a 1000uf cap and diode to help with the power, now it only flicks the relays once on startup but thats still to much

Put the pinModes in the correct place, and try a pull-down on the relay pins.