PHP Generate 4 Digit Unique Random Numbers Example

03-Apr-2023

.

Admin

Hi Guys

In this blog, i will tell you how to generate 4 digit unique random numbers.we are random function using in php to generate 4 random numbers.you can easy to create 4 unique random digit in php.

we are show generate 4 digit unique random numbers example.you can create the random number of Four digits in PHP.

i will show two different function to generate 4 random numbers.first generate 4 unique random numbers for function mt_rand() and second generate 4 unique random numbers for function rand().

here the following example of generate 4 digit unique random numbers

Example 1


here the example mt_rand() function using generate 4 digit unique random numbers

<?php

$fourRandomDigit = mt_rand(1000,9999);

echo $fourRandomDigit;

?>

Example 2

here the example rand() function using generate 4 digit unique random numbers

<?php

$fourRandomDigit = rand(1000,9999);

echo $fourRandomDigit;

?>

It will help you..

#PHP