PHP in HindiProgramming Language

How to Generate Random Number using PHP?

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;
?>

 

Related Articles

Leave a Reply

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

Back to top button
Close