PHP srand() - Math Functions

What is srand Function?

Explanation

The "srand()" function seeds a random number to the random number generator rand(). This function should be called only once, and should be called before the rand() function.

Syntax:


srand(seed)

In the above syntax "seed" is the optional value which can be a random number seed.

Example :


<?php
srand(mktime());
echo(rand());
?>
Result :

15067

In the above example the seed value is provided using the function mktime(), then a random number is generated.

PHP Topics


Ask Questions

Ask Question