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

The rand() function in PHP

Thisrand()The function generates a random number. You can also set a range to get a random number from a specific range.

Syntax

rand();
or
rand(min_range,max_range);

parameter

  • min_range-Default is 0. This is the lowest number to be returned.

  • max_range-This is the highest number to be returned.

returns

Thisrand()The function returns a random integer between min_range and max_range.

Example

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

Output Result

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

Example

Let's see another example-

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

Output Result

4<br>114