static public function generate($uid = 0, $hash = false)
    {
        if ($uid) {
            $e_uid = self::encode($uid);
            $e_uid_length = strlen($e_uid);
            $e_uid_length = str_pad($e_uid_length, 2, 0, STR_PAD_LEFT);
            $e_uid_pos = rand(10, 32 - $e_uid_length - 1);

            if (!$hash) {
                $hash = sha1(uniqid(rand(), true));
            }

            $code = $e_uid_pos . $e_uid_length;
            $code .= substr($hash, 0, $e_uid_pos - strlen($code));
            $code .= $e_uid;
            $code .= substr($hash, strlen($code));

            return $code;
        } else {
            return sha1(uniqid(rand(), true));
        }
    }