How to Generate a Random Number in PHP

PHP

mt_rand() the function used to generate the random number in PHP.

Syntax

<?php
mt_rand(min,max);

min: Optional. Specifies the lowest number to return. Default is 0.

max: Optional. Specifies the highest number to return. Max is 2147483647.

Example 1:

<?php
$random_number=mt_rand();
echo $random_number;

Example 2:

<?php
$random_number=mt_rand(100000,9999999);
echo $random_number;

The post How to Generate a Random Number in PHP appeared first on PHPGurukul.