Ejemplo n.º 1
0
Archivo: get.php Proyecto: Borvik/Munla
 /**
  * Generates a random string from the given set.
  * 
  * @param int $length
  *   The length of the string to create.
  * 
  * @param char $set
  *   The character set to use when generating the string.
  *   - d: digits
  *   - h: hex
  *   - u: alpha uppercase
  *   - l: alpha lowercase
  *   - o: alpha uppercase and lowercase only
  *   - A: alpha numeric uppercase
  *   - a: alpha numeric lowercase
  *   - m: mixed
  */
 public static function rand_string($length, $set = 'm')
 {
     $a = array('d', 'h', 'u', 'l', 'A', 'a', 'm', 'o');
     $s = 'm';
     if ($set != 'A') {
         $set = strtolower($set);
     }
     if (in_array($set, $a)) {
         $s = $set;
     }
     $random = '';
     mt_srand((double) microtime() * 1000000);
     $chars = get::getCharacterSet($s);
     while (strlen($random) < $length) {
         $random .= substr($chars, mt_rand() % strlen($chars), 1);
     }
     return $random;
 }