The srand() function is used to seed the random number generaror. Seeding initializes the random number generator. Most random number generators need initial seeding. In PHP, use of srand() function is optional as it is done automatically.
This function doen't have any return value.
srand ([ int $seed ] ) : void
|Sr.No||Parameter & Description|
an integer to be used as seed. If not given, a random number is given
This function doesn't return any value.
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
This example the random number generator is first initialized before employing rand() function−
<?php srand(5); echo "rand(1,100)=", rand(1,100); ?>
This may produce following result −
Following example uses current timestamp to initialize random number generator−
<?php srand(time()); echo "rand()=", rand(); ?>
This may produce following result−