示例#1
0
文件: UniqID.php 项目: kidaa30/redcat
 /**
  * Generate a random string of the specified size
  *
  * @param int $size The size of the requested random string
  *
  * @return string A string of the requested size
  */
 public function generate($size)
 {
     $result = '';
     while (Util::safeStrlen($result) < $size) {
         $result = uniqid($result, true);
     }
     return Util::safeSubstr($result, 0, $size);
 }
示例#2
0
 public function __construct()
 {
     $state = self::$state;
     if (function_exists('posix_times')) {
         $state .= serialize(posix_times());
     }
     if (!defined('HHVM_VERSION') && function_exists('zend_thread_id')) {
         $state .= zend_thread_id();
     }
     if (function_exists('hphp_get_thread_id')) {
         $state .= hphp_get_thread_id();
     }
     $state .= getmypid() . memory_get_usage();
     $state .= serialize($_ENV);
     $state .= serialize($_SERVER);
     $state .= count(debug_backtrace(false));
     self::$state = hash('sha512', $state, true);
     if (is_null(self::$counter)) {
         list(, self::$counter) = unpack("i", Util::safeSubstr(self::$state, 0, 4));
         $seed = $this->generate(Util::safeStrlen(dechex(PHP_INT_MAX)));
         list(, self::$counter) = unpack("i", $seed);
     }
 }
示例#3
0
文件: Hash.php 项目: kidaa30/redcat
 /**
  * Get the block size (the size of the individual blocks used for the mixing)
  *
  * @return int The block size
  */
 protected function getPartSize()
 {
     return Util::safeStrlen(hash($this->hash, '', true));
 }