How to Generate Random Number using PHP?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Problem:- How to Generate Random Number using PHP? You want to generate a random number within a range of number. You can check code we have written below.

Solution – Generate Random Number using PHP

<?php
$start_no = 0000;
$end_no	= 9999;
$random_no = mt_rand($start_no, $end_no);
echo $random_no;
?>

How it Work?

mt_rand() function return the number between 1st argument and 2nd argument . Generating random numberis useful when you want to verify mail or phone number in your form or you want to display random images on a page every time your visitor refresh. You also can call mt_rand() without argument so it will return from 0 to maximum number.

<?php
$random_no = mt_rand();
echo $random_no;
?>

इसे भी पढ़े – SBI Account का Balance कैसे चेक करे?

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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