# rand() function in PHP

PHPProgrammingServer Side Programming

The rand() function gets a random number. You can also set a range to get random number from that particular range.

## Syntax

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

## Parameters

• min_range − Default is 0. This is the lowest number to be Returned.

• max_range − This is the highest number to be Returned.

## Return

The rand() function Returns a random integer between min_range and max_range.

## Example

Live Demo

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

## Output

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

## Example

Let us see another example −

Live Demo

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

## Output

4<br>114
Published on 09-Nov-2018 16:48:45