title: How can I create a unique random string in laravel 5
body: <p>I am new to laravel 5. I am working on a project where I want to assign some random-readable <strong>unique</strong> string to each application. I have knowledge of the each application id which may be use as a seed. Since the app is going to be use within the company I don't worry much about security. I expect the table size to grow so my goal is to achieve uniqueness as much as possible because the field in DB is unique. A code like (EN1A20, EN12ZOV etc). If the function can allow me to pass the length of the string I want to return, that would be really awesome. </p>
  
  <p><strong>Edit</strong>
  Shown below is my attempt to the problem</p>
  
  <pre><code>private function generate_app_code($application_id) { 
          $token = $this-&gt;getToken(6, $application_id);
          $code = 'EN'. $token . substr(strftime("%Y", time()),2);
  
          return $code;
      }
  
      private function getToken($length, $seed){    
          $token = "";
          $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
          $codeAlphabet.= "0123456789";
  
          mt_srand($seed);      // Call once. Good since $application_id is unique.
  
          for($i=0;$i&lt;$length;$i++){
              $token .= $codeAlphabet[mt_rand(0,strlen($codeAlphabet)-1)];
          }
          return $token;
      }
  </code></pre>
  
  <p>Can the code above do the trick?</p>
  
  <p><strong>Edit</strong> </p>
  
  <p>Actually I borrowed ideas from this post <a href="https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string">PHP: How to generate a random, unique, alphanumeric string?</a> to come out with the methods above but the post does not entirely address my issues. My goal is to generate a string of length say 6 to 8 (Alphanumeric and readable). This string would be use by my admin for query purposes.  In my function I have mt_srand($seed) to seed the random number generator where seed is my application_id. It is possible to get duplicate $token.</p>
  
  <p>Appreciate help.</p>