English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Fonction rand() dans PHP

Lerand()La fonction obtient un nombre aléatoire. Vous pouvez également définir une plage pour obtenir un nombre aléatoire à partir de cette plage spécifique.

Syntaxe

rand();
ou
rand(min_range,max_range);

paramètre

  • min_range-Par défaut, il est de 0. C'est le nombre le plus bas à retourner.

  • max_range-C'est le nombre le plus élevé à retourner.

retourne

Lerand()La fonction retourne un entier aléatoire entre min_range et max_range.

Exemple

<?php
   echo(rand() . "<br>");
   echo(rand() . "<br>");
   echo(rand() . "<br>");
   echo(rand() . "<br>");
   echo(rand() . "<br>");
   echo(rand());
?>

Résultat de la sortie

1581227270<br>1094001227<br>306337052<br>151211887<br>7894804<br>115835633

Exemple

Voyons un autre exemple-

<?php
   echo(rand(2, 5)) . "<br>";
   echo(rand(90, 190));
?>

Résultat de la sortie

4<br>114