Advertisement
carbonize

Random Characters

Feb 7th, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2. function randomString($strLen = 32)
  3. {
  4.   // Create our character array
  5.   $chrs = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
  6.  
  7.   // Just to make the output even more random
  8.   shuffle($chrs);
  9.  
  10.   // Create a holder for our string
  11.   $randStr = '';
  12.  
  13.   // Now loop through the desired number of characters for our string
  14.   for($i=0;$i<$strLen;$i++)
  15.   {
  16.     $randStr .= $chrs[mt_rand(0, (count($chrs) - 1))];
  17.   }
  18.   return $randStr;
  19. }
  20.  
  21. echo randomString();
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement