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

mt_srand

Description

The mt_srand of Random for PHP seeds the Mersenne Twister Random Number Generator.

The mt_srand of Random for PHP note: There is no need to seed the random number generator with mt_srand() as this is done automatically..

Syntax

mt_srand ([ int $seed [, 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.

ConstantDescription
MT_RAND_MT19937Uses the fixed, correct, Mersenne Twister implementation, available as of PHP 7.1.0.
MT_RAND_PHPUses an incorrect Mersenne Twister implementation which was used as the default up till PHP 7.1.0. This mode is available for backward compatibility.

Return

No value is returned.

Examples

1 · void

<?

mt_srand();

$mt_randreturn = mt_rand();

echo $mt_randreturn;

?>
1033771279

2 · seed

<?

$seed = time();

mt_srand($seed);

$mt_randreturn = mt_rand();

echo $mt_randreturn;

?>
307290367

3 · mode

<?

$seed = time();
$mode = MT_RAND_PHP;

mt_srand($seed, $mode);

$mt_randreturn = mt_rand();

echo $mt_randreturn;

?>
307290367
HomeMenu