PHP - Explain with code how to generate a random number from php.

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);
PHP - Explain about Type Juggling in php with an example
Explain about Type Juggling in php with an example - The ternary conditional operator is of the form.....
PHP - Difference between Reply-to and Return-path in the headers of a mail function.
Difference between Reply-to and Return-path in the headers of a mail function - Reply-to is the address where the email needs to be delivered...
PHP - How to store the uploaded file to the final location
How to store the uploaded file to the final location - Files in PHP can be uploaded using move_uploaded_file ( string filename, string destination).....
Post your comment