On both 32 and 64-bit systems (OS X and Linux), mt_getrandmax() returns 2147483647 for me, i.e. ~2^31.
mt_getrandmax
(PHP 4, PHP 5)
mt_getrandmax — Show largest possible random value
Descrierea
int mt_getrandmax
( void
)
Returns the maximum value that can be returned by a call to mt_rand().
Valorile întoarse
Returns the maximum random value returned by mt_rand()
Exemple
Example #1 Calculate a random floating-point number
<?php
function randomFloat($min = 0, $max = 1) {
return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}
var_dump(randomFloat());
var_dump(randomFloat(2, 20));
?>
Exemplul de mai sus va afișa ceva similar cu:
float(0.91601131712832) float(16.511210331931)
Vedeți de asemenea
- mt_rand() - Generate a better random value
- mt_srand() - Seed the better random number generator
- getrandmax() - Show largest possible random value
marcus at synchromedia dot co dot uk
10-Aug-2011 01:41
