io uso questa funzione per generare una stringa casuale alfanumerica, forse può esserti utile:

codice:
	function genActivationCode($length = 16) {
		$code = "";
		$possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
  		$i = 0;
  		while ($i < $length) { 
			$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
			if (!strstr($code, $char)) { 
      			$code .= $char;
      			$i++;
    		}

  		}
		return $code;
	}