-->

  • PHP random number



    PHP random number




    The PHP rand() function generates a random number :
    The rand() is an inbuilt-function in PHP used to generate a random number.  PHP random number



    Syntax

    rand()



    Example 

    echo(rand());

    echo "<br>";




    ?>



    </body>
    </html>




    465768456







    To get more control over the random number, you can add the optional min and max parameters to specify the lowest integer and the highest integer to be returned.

    For example, if you want a random integer between 10 and 100 (inclusive), use rand(10, 100):




    Example 



    echo(rand(10, 200));

    echo "<br>";




    ?>




    </html>





    154


    Note

    If the min and max value is not specified, default is 0 and getrandmax() respectively.


    Example


    • rand() will return a random integer between 0 and getrandmax().
    • rand(15,35) will return a random integer in the range [15,35].




    Example 

    $rndmNmbr = rand();

    // print

    print_r($rndmNmbr);

    // new line

    echo "<br>";

     // Generating a random number in a specified range

    $rndmNmbr = rand(12, 55);

    // print

     print_r ($rndmNmbr);


    ?>




    </html>




    56677465
    108


    Note :
    The output of the code may change every time it is run. So the output may not match with the specified output.



    Output 


    4546345
    45







    Video on This Topic :- Soon


    I hope you liked this post, then you should not forget to share this post at all.
    Thank you so much :-)



  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.