downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

mt_rand> <min
[edit] Last updated: Fri, 14 Jun 2013

view this page in

mt_getrandmax

(PHP 4, PHP 5)

mt_getrandmaxLa plus grande valeur aléatoire possible

Description

int mt_getrandmax ( void )

Retourne la plus grande valeur aléatoire possible que peut retourner la fonction mt_rand().

Valeurs de retour

Retourne la plus grande valeur aléatoire possible retournée par la fonction mt_rand()

Exemples

Exemple #1 Calcule un nombre flottant aléatoire

<?php
function randomFloat($min 0$max 1) {
    return 
$min mt_rand() / mt_getrandmax() * ($max $min);
}

var_dump(randomFloat());
var_dump(randomFloat(220));
?>

L'exemple ci-dessus va afficher quelque chose de similaire à :

float(0.91601131712832)
float(16.511210331931)

Voir aussi

  • mt_rand() - Génère une meilleure valeur aléatoire
  • mt_srand() - Initialise une meilleure valeur aléatoire
  • getrandmax() - Plus grande valeur aléatoire possible



add a note add a note User Contributed Notes mt_getrandmax - [2 notes]
up
1
Anonymous
1 month ago
The max on a Windows 7 x64 machine is also 2147483647.
up
7
marcus at synchromedia dot co dot uk
1 year ago
On both 32 and 64-bit systems (OS X and Linux), mt_getrandmax() returns 2147483647 for me, i.e. ~2^31.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites