mt_srand


URL apg

SEEDS the MTRNG, Mersenne Twister Random Number Generator.

Seeds the random number generator with seed or with a random value if no seed is given.




RANDOM NUMBERS

are numbers that occur in a sequence such that two conditions are met:

1 . the values are uniformly distributed over a defined interval or set.
2 . it is impossible to predict future values based on past or present ones.

Random numbers are important in statistical analysis and probability theory.

There is no need to use  srand  or  mt_srand  as this is done automatically when we need to seed the random number generator.

Since PHP 7.1.0,  srand  becames an alias of  mt_srand .

Since PHP 7.1.0  mt_rand  has been updated to use the fixed, correct, version of the Mersenne Twister Algorithm.

To fall back to the old behaviour, use  mt_srand  with MT_RAND_PHP as the second parameter.

This function uses the MTRNG, Mersenne Twister Random Number:

   Mersenne Twister  !



<?php

void mt_srand 
int $seed 
                         
int $mode MT_RAND_MT19937 )

where,

$seed Arbitrary INTEGER value to be used as seed
            
$mode 
CONSTANT to specify the implementation 
                 of the algorithm to be used
                    
SEE the below TABLE )
            
?>

$seed


Arbitrary INTEGER value to be used as seed.



$mode


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


CONSTANT VALUE DESCRIPTION
MT_RAND_MT19937 0 Uses the fixed, correct, Mersenne Twister implementation.
Available as of PHP 7.1.0.
MT_RAND_PHP 1 Uses an incorrect Mersenne Twister implementation.
Used as the
default up till PHP 7.1.0.
This mode is available for backward compatibility.
ed48

  1 EXERCISE   

<?php
 
$mtsrnd01  
mt_srand();

var_dump($mtsrnd01);

?> 

 RESULT   

NULL

... is returned always.

  2 EXERCISE   

<?php

$seed02 
100;

$mode mt_rand(01);
// MT_RAND_MT19937 = 0;
// MT_RAND_PHP = 1
 
$mtsrnd02  mt_srand($seed02);

var_dump($mtsrnd02);

?> 

 RESULT   

NULL

... is returned always.