What is the purpose of using srand() in PHP for generating random numbers?

When generating random numbers in PHP, using the srand() function is important to seed the random number generator. By seeding the generator with srand(), you can ensure that the sequence of random numbers generated is different each time the script is run. This helps to avoid predictability and improve the randomness of the generated numbers.

// Seed the random number generator
srand(time());

// Generate a random number between 1 and 100
$randomNumber = rand(1, 100);

echo $randomNumber;