What is the difference between mt_rand and random_int in PHP?

The main difference between mt_rand and random_int in PHP is the underlying algorithm used to generate random numbers. mt_rand uses the Mersenne Twister algorithm, which is a pseudorandom number generator, while random_int uses the cryptographically secure random number generator provided by the operating system. If you require random numbers for security-sensitive applications, it is recommended to use random_int for better randomness and unpredictability.

// Using random_int to generate a cryptographically secure random number
$randomNumber = random_int(1, 100);
echo $randomNumber;