/**
* hash 散列帮助类
*/
class Helper_Hash
{
/**
* 生成随机的hash字符串
* @param int $length
*/
static function setVerifyKey($length = 16)
{
// first three characters is capitalize
$key = chr(mt_rand(65,90)).chr(mt_rand(65,90)).chr(mt_rand(65,90));
// rest are either 0-9 or a-z
for($k = 0; $k < $length - 3; $k++)
{
$probab = mt_rand(1,16);
if($probab <= 11)
{
// a-z probability is 80%
$key .= chr(mt_rand(97,122));
}
else
{
// 0-9 probability is 20%
$key .= chr(mt_rand(48, 57));
}
}
return $key;
}
/**
* 根据数字生成一个3层深度的目录路径
* @param int $keyid
*/
static function hashDIR($keyid)
{
$keyid = abs(intval($keyid));
$keyid = sprintf("%09d", $keyid);
$dir1 = substr($keyid, 0, 3);
$dir2 = substr($keyid, 3, 2);
$dir3 = substr($keyid, 5, 2);
return $dir1.'/'.$dir2.'/'.$dir3.'/';
}
}