title: Generate a random number with pre-defined length PHP
body: <p>I'm trying to create a function using mt_rand() in order to generate a truly random number, since rand() just isn't suffice.</p>
  
  <p>The problem is I need to pre-define the length of the number, say I need a 10 digit random number.</p>
  
  <p>Anyway, I've been messing around and this is what I've come up with:</p>
  
  <pre><code>    function randomNumber($length) {
          $min = str_repeat(0, $length-1) . 1;
          $max = str_repeat(9, $length);
          return mt_rand($min, $max);   
      }
  </code></pre>
  
  <p>In theory that should work (as far as I can tell), but it doesn't. The length is completely random and it also throws out negative values.</p>
  
  <p>Any ideas?</p>