What is the difference between "rands" in PHP?

2

I would like to know what diff rand of mt_rand and mt_srand; And if you have any other rand.

    
asked by anonymous 27.09.2016 / 03:50

1 answer

2

mt_rand : Improved random number generator

<?php
   echo mt_rand() . "\n";
   echo mt_rand() . "\n";
   echo mt_rand(5, 15);
?>

mt_srand : Seed the improved random number generator

<?php
   // semente de microsegundos
   function make_seed()
   {
      list($usec, $sec) = explode(' ', microtime());
      return (float) $sec + ((float) $usec * 100000);
   }
   mt_srand(make_seed());
   $randval = mt_rand();
?>

srand : Seed the random number generator

<?php
   // Semeia com microsegundos
   function make_seed()
   {
      list($usec, $sec) = explode(' ', microtime());
      return $sec + $usec * 1000000;
   }
   srand(make_seed());
   $randval = rand();
?>
    
27.09.2016 / 03:54