srand
Description
NOTE: There is no need to seed the random number generator with srand() as this is done automatically.
Syntax
srand(
?int $seed = null,
int $mode = MT_RAND_MT19937
): voidParameters
seed
An arbitrary integer seed value.
mode
Use one of the following constants to specify the implementation of the algorithm to use.
| Value | Constant | Description |
|---|---|---|
| 0 | MT_RAND_MT19937 | Uses correct Mersenne Twister implementation. |
| 1 | MT_RAND_PHP | Uses incorrect Mersenne Twister implementation. Available for backward compatibility. |
Return
No value is returned.
Examples
1 · void
<? srand(); $randreturn = rand(); echo $randreturn;
1694434222
2 · seed
<? $seed = time(); srand($seed); $randreturn = rand(); echo $randreturn;
1489637316
3 · mode · MT_RAND_MT19937
<? $seed = time(); $mode = MT_RAND_MT19937; srand($seed, $mode); $randreturn = rand(); echo $randreturn;
1489637316
4 · mode · MT_RAND_PHP
<? $seed = time(); $mode = MT_RAND_PHP; srand($seed, $mode); $randreturn = rand(); echo $randreturn;
1489637316