PHP » Miscellaneous » srand()

Syntax:
void srand([int seed])
seed
Seed for the random number generator.

Seeds the random number generator.

srand() seeds the random number generator. Since PHP 4.2.0 this is unnecessary, since PHP does the seeding automatically. The seed parameter is also optional.

Examples

Code:
<?php

$seed = explode(" ", microtime());
$seed = $seed[0] * 1000000;
print "seed: $seed";
srand($seed);

?>
Output:
seed: 20071
Explanation:

The microseconds component of the value return from microtime() is used to create a seed that changes often.

See Also: