Home >>PHP Math Functions >PHP srand() Function

PHP srand() Function

PHP srand() Function

PHP srand() function in PHP is used to seed the random number generator function rand(). It sets the starting point for rand() to produce a series of pseudo-random integers. It seeds the random number generator with seed(argument) or with a random value if no seed(argument) is passed. It accepts only a single parameter seed that is an optional parameter and is of integer type.

Syntax:

  Syntax:  srand($seed);

Parameter Values

Parameter Description
seed This is an optional parameter. This parameter defines the seed value.

Here is an example of srand() function in PHP:

<html>
<body>

<?php

srand(mktime());
echo rand();

?>

</body>
</html>
Output:
2057534105

Here is another example of srand() function in PHP:

<html>
<body>

<?php

srand(10);

echo rand(1,100);

?>

</body>
</html>
Output:
38

No Sidebar ads