Advertisement
cuonic

Rand String Generator - Buggy

Jun 18th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2.  
  3. function genRandomString($length) {
  4.    $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUXWXYZabcdefghijklmnopqrstuvwxyz';
  5.    $string = "";    
  6.  
  7.    for ($p = 0; $p < $length; $p++) {
  8.        $string .= $characters[mt_rand(0, strlen($characters))];
  9.    }
  10.  
  11.    return $string;
  12. }
  13.  
  14. $i = 0;
  15.  
  16. $total = 100;
  17.  
  18. while($i < $total)
  19. {
  20.     $code = genRandomString(15);
  21.     $length = strlen($code);
  22.    
  23.     if($length == 15)
  24.     {
  25.         echo "<span style=\"background-color: green;\">$code - $length chars</span><br/>";
  26.     }
  27.     else
  28.     {
  29.         echo "<span style=\"background-color: red;\">$code - $length chars</span><br/>";
  30.     }
  31.  
  32.     $i++;
  33. }
  34.  
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement