srand


qr-code apg

GENERATES a seed for the 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  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 .



<?php

void srand
int $seed 0int $mode MT_RAND_MT19937 )

where,

$seed Arbitrary INTEGER value to be used as seed

$mode 
The mode to be used
              
SEE the below TABLE )

?>

$seed


Arbitrary INTEGER value to be used as seed.



$mode


Arbitrary INTEGER mode to be used as seed.



INTERNAL CONSTANTS
PHP 8.2.22
80222
CONTANT NAMEVALUE
MT_RAND_MT199370
MT_RAND_PHP1
ed48


  1 EXERCISE   

<?php
 
$srd01  
srand(00);

var_dump($srd01);

?> 

 RESULT   

NULL

... is returned

  2 EXERCISE   

<?php

$seed02 
100;

$mode02 MT_RAND_PHP;
 
$srd02  srand($seed02$mode02);

var_dump($srd02);

?> 

 RESULT   

NULL

... is returned

  3 EXERCISE   

<?php

$seed03 
120;

$mode03 30;
 
$srd03  srand($seed03$mode03);

var_dump($srd03);

?> 

  4 EXERCISE   

<?php

$srd04  
srand();

var_dump($srd04);

?>