Generate random numbers in PHP
There are several ways of generating random numbers in PHP. We can use a rand() function which takes two parameters(optional) to generate random numbers. But there is one more function which is more efficient mt_rand() which also takes two optional parameters, minimum and maximum value. I am going to generate some random numbers using mt_rand() function.
<?php
//Generating 10 random numbers
for($i = 0; $i < 10; $i++)
{
//Generates random number between 0 and 50
echo mt_rand(0, 50) . '---';
}
?>
Here is the output of the above code:
Subscribe to:
Posts (Atom)
