PHP how to generate random numbers?

I am explaining you, how to generate random numbers in PHP. I will use rand() function to generate random numbers. rand() function can able to use to generate a random number with specific range like starting number is 1 and ending number id 999 so it will generate random number in between. you can use any number as per requirement.
if you will not provide range so it will generate large number.

Syntax :

rand();
rand(min,max); 
//min minimum integer number
//max maximum integer number

Example :

<?php
  echo rand(1, 50) . "<br>";
  echo rand(51, 250) . "<br>";
  echo rand();
?>

Output :

49
166
591487216

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 2 =