HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

srand

Description

The srand of Random for PHP seed the random number generator.

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
): void

Parameters

seed

An arbitrary integer seed value.

mode

Use one of the following constants to specify the implementation of the algorithm to use.

ValueConstantDescription
0MT_RAND_MT19937Uses correct Mersenne Twister implementation.
1MT_RAND_PHPUses 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