title: PHP Random String verification from Database
body: <p>I am working on a url Shortener and Currently i am facing a problem with Random Generated String. Things i want to do is:</p>
  
  <ol>
  <li>Generate A Random String [ Already Done ]</li>
  <li>Searching into Database Whether it exists or not [ Already Done ]</li>
  <li>If it already Exists, Generate a new one and Again Proceed for checking [ Stacked !]</li>
  <li>if Its Unique, Go for Next Process </li>
  </ol>
  
  <p>Now This Is the code is used for generate Random String </p>
  
  <pre><code>function randString($length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
  $str = '';
  $count = strlen($charset);
  while ($length--) {
      $str .= $charset[mt_rand(0, $count-1)];
  }
  return $str; }
  </code></pre>
  
  <p>What can i do now?</p>