fonction rand () de PHP
Exemples
Génère un nombre aléatoire:
<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>
Exécution instance »
Définition et utilisation
fonction rand () génère un nombre aléatoire.
Astuce: Si vous voulez un entre 10 et 100 (y compris 10 et 100) du nombre aléatoire, utilisez rand (10,100).
Astuce: mt_rand () fonction est un meilleur choix pour générer des valeurs aléatoires, renvoyant un résultat de la vitesse de rand () 4 fois la fonction.
grammaire
rand();
or
rand( min,max );
or
rand( min,max );
参数 | 描述 |
---|---|
min | 可选。规定返回的最小数。默认是 0。 |
max | 可选。规定返回的最大数。默认是 getrandmax() 。 |
détails techniques
Retours: | Entre min (ou 0) et max (ou mt_getrandmax ()) (inclus) entre le nombre entier aléatoire. |
---|---|
Type de retour: | entier |
PHP version: | 4+ |
PHP Mise à jour du journal: | PHP 4.2.0: générateur de nombres aléatoires est automatiquement ensemencée. |
PHP Math Reference