PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » PHP » Make Random Number

Make Random Number

function getRandomId($min = NULL, $max = NULL) {
       if (is_numeric($min) && is_numeric($max)) {
               return mt_rand($min, $max);
       }
       else {
               return mt_rand();
       }
}

Subscribe to The Thread

  1. doesn’t

    rand(1, 50)

    do the same thing?

  2. Also,
    mt_rand(0,99) do the same?

    I hope to get a perfect random number, I generally use,
    function rand_num() {
    $rand_num = md5(mt_rand(0,99) . mt_rand(99,9999). time());
    return $rand_num;
    }

    To make some email validation or generating random hash I use it.

  3. Jonathan

    Wtf ? whats is the great of that function ?

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~