Generate 4,6,8,10 unique random number in PHP

To generate unique random number in PHP; Through this tutorial, i am going to show you how to generate 2,4,6,10,12 digit unique random number in PHP.

Generate unique random number in PHP

Using the php rand() and mt_rand() function, you can generate 2,4,6,10,12, etc digit unique random number in PHP.

  • The rand() is inbuilt PHP function, which used to generate a random integer number.
  • The mt_rand () is the inbuilt PHP function, which is used to generate random integer numbers. This function uses the Mersenne Twister algorithm.

Generate unique random number in PHP using rand()

Let’s see the following example to generate unique random number in php using rand() function; is as follows:

<!DOCTYPE html>
<html>
<body>
 
<?php
 
echo(rand() . "<br>");
 
echo(rand(10,99) . "<br>"); // generate 2 digit unique random number in php
 
echo(rand(1000,9999) . "<br>"); // generate 4 digit unique random number in php
 
echo(rand(100000,999999) . "<br>"); // generate 4 digit unique random number in php
 
echo(rand(10000000,99999999) . "<br>"); // generate 8 digit unique random number in php
 
?>
 
</body>
</html>

Generate unique random number in PHP using mt_rand()

Let’s see the following example to generate unique random number in php using mt_rand() function; is as follows:

<!DOCTYPE html>
<html>
<body>
 
<?php
 
echo(rand() . "<br>");
 
echo(rand(10,99) . "<br>"); // generate 2 digit unique random number in php
 
echo(rand(1000,9999) . "<br>"); // generate 4 digit unique random number in php
 
echo(rand(100000,999999) . "<br>"); // generate 4 digit unique random number in php
 
echo(rand(10000000,99999999) . "<br>"); // generate 8 digit unique random number in php
 
?>
 
</body>
</html>

Recommended PHP Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.