Explain how to generate a random number from php.
The function rand() can be used to generate random number. If the random number needs to be in between some range, the parameters can be specified.
<?php
Echo rand(10,20);
?>
Explain how to generate a random number from php.
Random number is generated by using the function rand(),mt_rand(). If the function is used without sending a parameter, a random number between 0 and RAND_MAX is returned.
Example:echo rand();
To return a random number between 120 and 200 inclusive, the code snippet is
echo rand(120,200);
For returning a random number using the Mersenne Twister algorithm, use mt_rand().
The function srand() is used to seed the random number, and it must be used once in a script and before the rand() function. If the randomness of the seed is greater, more random numbers can be generated.
Example:srand((double)microtime()*1000000);
echo rand(0,100);