What is the difference between "rands" in PHP?

Asked

Viewed 53 times

2

I would like to know what differs the Rand from mt_rand and mt_srand; And if you have any other Rand.

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: Sow 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: Sow 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();
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.