Saleh Saleh - 3 months ago 10
PHP Question

How I can generate 6 random numbers - php?

I want to generate only 6 random numbers [length = 6] using

mt_rand()
function.

this function take only 2 parameters - Min value, Max value.

How I can do it.

Thanks in advance.

Answer

Something like this ?

<?php 
$a = mt_rand(100000,999999); 
?>

Or this, then the first digit can be 0 in first example can it only be 1 to 9

for ($i = 0; $i<6; $i++) 
{
    $a .= mt_rand(0,9);
}
Comments