Q:

Generate random numbers in PHP

belongs to collection: PHP Miscellaneous

0

Generate random numbers in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

To generate random number in PHP, we can use rand() function – it returns a random number between 0 to getrandmax(). We can also specify the minimum and maximum values to generate the random numbers between them.

<?php
    //generating 10 random number
    echo "Random numbers are: \n";
    for($count=0; $count<10; $count++)
        echo (rand() . " ");

    //generating 10 random numbers between 50 to 99
    echo "\nRandom numbers b/w 50 to 99 are: \n";
    for($count=0; $count<10; $count++)
        echo (rand(50, 99) . " ");
?>

Output

Random numbers are:
477886177 1803134402 1833202175 1581092595 342280099 2092682811 
361945816 379084078 468756937 1242809286
Random numbers b/w 50 to 99 are:
98 74 50 72 77 61 75 50 75 96

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Miscellaneous

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Find remote IP address in PHP... >>
<< Find similarity of two strings in PHP...