Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Christian

By: a guest on Jan 10th, 2009  |  syntax: PHP  |  size: 0.49 KB  |  hits: 465  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php
  2. // Den gamle
  3. function RandStr($len=8)
  4.         {
  5.                 $char = range('a', 'z');
  6.                 shuffle($char);
  7.                
  8.                 for($i=0; $i<$len; $i++)
  9.                         {
  10.                                 $str .= $char[0];
  11.                
  12.                                 shuffle($char);
  13.                         }
  14.                        
  15.                 return $str;
  16.         }
  17.  
  18. echo RandStr();
  19. ?>
  20.  
  21. <?php
  22. // Den nye
  23. function RandStr2($len=8)
  24.         {
  25.                 $char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";      
  26.                
  27.                 for($i=0; $i<$len; $i++)
  28.                         {
  29.                                 $str .= $char[rand(0, strlen($char))];
  30.                         }
  31.                        
  32.                 return $str;
  33.         }
  34.  
  35. echo RandStr2();
  36. ?>