mt_srand

Seeds the Mersenne Twister Random Number Generator

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.

Constant Description
MT_RAND_MT19937 Uses the fixed, correct, Mersenne Twister implementation, available as of PHP 7.1.0.
MT_RAND_PHP Uses 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

void

<?

mt_srand();

$mt_randreturn = mt_rand();

echo $mt_randreturn;

?>
2121394060

seed

<?

$seed = time();

mt_srand($seed);

$mt_randreturn = mt_rand();

echo $mt_randreturn;

?>
1763100363

mode

<?

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

mt_srand($seed, $mode);

$mt_randreturn = mt_rand();

echo $mt_randreturn;

?>
1763100363

PHP

Home Menu