Need to make my program send random OTPs to my phone number

Hey guys,
I have already posted in this forum about the same problem I had with a piece of my program which needs to send a random 4 digit otp to my mobile number and then I input the otp to my keypad and then it prints access granted or denied if entered right or wrong. Many of the users helped me with the code but then it doesn't send the random number.
Here's the code:

#include <LiquidCrystal.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <Keypad.h>

const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int getFingerprintIDez();
SoftwareSerial mySerial(10, 11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
                            {'1','2','3'},
                            {'4','5','6'},
                            {'7','8','9'},
                            {'#','0','*'}
                         };
byte rowPins[ROWS] = { 33, 32, 31, 30 };
byte colPins[COLS] = { 36, 35, 34 }; 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char* storedPassword = "5432" ;
void setup()  
{
   // For Yun/Leo/Micro/Zero/...
  Serial.begin(9600); // set baud rate for serial monitor 
 lcd.begin(16, 2);
  Serial.println("Adafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  
  Serial.println("Waiting for valid finger...");
  Serial1.begin(9600); 
   lcd.print("Place the finger");
   lcd.clear();
}
void loop()
{
  getFingerprintIDez();
  delay(50);
 
   if (Serial.available()) {
    Serial1.write(Serial.read());
  }
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
   if (char* enteredPassword = lookForPassword(keypad))
  {
    Serial.println(enteredPassword);
    if (strcmp(enteredPassword, storedPassword) == 0)
    {
      Serial.println(F("ACCESS GRANTED"));
      lcd.clear();
      lcd.print(F("ACCESS GRANTED"));
    }
    else
    {
      Serial.println(F("ACCESS DENIED"));
      lcd.clear();
      lcd.print(F("ACCESS DENIED"));
    }
  }


}
uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
    } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
 
   
     
   Serial1.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Serial1.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
  delay(1000);
  Serial1.println(storedPassword);// The SMS text you want to send
  delay(100);
   Serial1.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  
  Serial.println("ENTER OTP");
  lcd.print(("ENTER OTP"));
  
  
  return finger.fingerID; 
}
char* lookForPassword(Keypad& kpd)
{
  static char password[5];
  static int idx = 0;
  if(char key = kpd.getKey())
  {
    if (key == '#')
    {
      idx = 0;
      return password;
    }
    if (isDigit(key))
    {
      password[idx++] = key;
      password[idx] = '\0';
      if (idx > 3)
      {
        idx = 0;
        return password;
      }
    }
     lcd.setCursor(1,0);
  lcd.print(key);
  }
  return nullptr;
 
}

How do I put the random() and randomSeed() function in here?

How do I put the random() and randomSeed() function in here?

Which variable do you need to make random ?

UKHeliBob:
Which variable do you need to make random ?

the random () function.

Do you mean that the random number sequence repeats every time you start up? That is because it is not truly random, it uses a pseudo random number algorithm.

The random function already outputs a random value. You don't need to do anything to make it random.

I think you must have misunderstood the question. You say you have some variable in your code to be sent and you want that to be random. What random thing do you want to send? Just set it equal to the return from random.

someVar = random(1,10);

Now someVar has a random value between from 1 to 9.

Yes. for that I did try using
randomSeed(Analog(0)); in the setup
this worked and gave me different random numbers

Ok. So what exactly is the problem then?

I'm sorry. I meant I tried randomSeed() in a different program to see if it works. It did.
Here, I want to make the "storedPassword" variable to be able to use the random() function.
Will this be possible?

Aakarsh:
I'm sorry. I meant I tried randomSeed() in a different program to see if it works. It did.
Here, I want to make the "storedPassword" variable to be able to use the random() function.
Will this be possible?

What is the point of a random stored password? Nobody could ever guess it.

aarg:
What is the point of a random stored password? Nobody could ever guess it.

xD
I'll change it to "OTP".
I don't want the same password. Like a one time password. It needs to change everytime

You have to break it down into two parts - generating a random character, and generating a string of characters. A random character is just a random byte sized integer in the ASCII range that you want to restrict it to. This is too easy to give you code for.

Aakarsh:
xD
I'll change it to "OTP".
I don't want the same password. Like a one time password. It needs to change everytime

char OTP[5] = "test";

void setup() 
{
  Serial.begin(115200);
  randomSeed(analogRead(A0));
  updateOTP();
  Serial.println(OTP);
}

void loop() 
{

}

void updateOTP()
{
  char newString [5];
  for (int i = 0; i < sizeof(newString); i++)
  {
    if (i == sizeof(newString) - 1)
    {
      newString[i] = '\0';
    }
    else
    {
      newString[i] = random('0',':');
    }
  }
  strcpy(OTP, newString);
}

That function seems over complicated to me

How about

void updateOTP()
{
  for (int i = 0; i < sizeof(OTP) - 1; i++)
  {
    OTP[i] = random(48, 58);
  }
  OTP[4] = '\0';
}