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

When generating random numbers in PHP, it is important to use the srand function to seed the random number generator. This ensures that the sequence of random numbers generated is not predictable and truly random. Without using srand, the random numbers generated may be the same each time the script is run, which can lead to security vulnerabilities or inaccurate results in applications that rely on randomness.

<?php
// Seed the random number generator
srand(time());

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

echo "Random Number: $randomNumber";
?>