.


Divya

rand () Function in PHP


The rand() function is used to generates a random integer.

Real world Example

For OTP (One time Password) integration in our project we need rand () function. For OTP integration first we need to generates a 4 digit or 6 digit number.

Let's see how to generates a 4 digit number.

<!DOCTYPE html>
<html>
<body>
<?php
$random_number=rand(1000, 9999);
echo $random_number;
?>
</body>
</html>

To generates a 6 digit number.

<!DOCTYPE html>
<html>
<body>
<?php
$random_number=rand(100000, 999999);
echo $random_number;
?>
</body>
</html>


.