Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to generate a random number in PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 350
    Comment on it

    Hello friends,

    Today we learn how to generate a random number in PHP. In PHP, following function are used to generate random numbers.

    • rand():
      rand() function is used to display a random number.
      Syntax:
      rand();
      Or you can also write the syntax as follows:
      rand(min,max);
      In above function two parameter are there:
      - min: It is a optional parameter. min is the minimum number that is returned by the function. Default value is 0.
      - max: max is also an optional parameter. It is the maximum value of number that is returned by the function. Default value is getrandmax().
    • mt_rand():
      mt_rand() function is also used to display the random number with the help of Mersenne Twister algorithm. It execute 4 times faster than the rand() function and also produce better random number.
      Syntax:
      mt_rand();

      or you can write the syntax as follows:

      mt_rand(min,max);

      In above function two parameter are there:
      - min: It is a optional parameter. min is the minimum number that is returned by the function. Default value is 0.
      - max: max is also an optional parameter. It is the maximum value of number that is returned by the function. Default value is getrandmax().

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: