-- seek 随机种子字符串(建议请求参数md5)
function batches:random(seed, length)
    local resty_random = require "resty.random"
    local random_bytes = resty_random.bytes(length / 2) -- 每个字节对应两位十六进制字符
    local random_hex = ""
    for i = 1, #random_bytes do
        random_hex = random_hex .. string.format("%02x", string.byte(random_bytes, i))
    end
    -- 加入毫秒时间 用户提交参数;base64编码,增加唯一性
    random_hex = ngx.encode_base64(ngx.md5((ngx.now() * 1000) .. random_hex .. seed) .. random_hex)
    if #random_hex <= length then
        -- 如果random_hex小于所需长度
        local new_str = ""
        -- 循环相差长度次数,拼接random_hex md5值
        for i = 1, length - #random_hex, 1 do
            new_str = new_str .. ngx.md5(random_hex)
        end
        -- base64编码,以便截取字符串
        random_hex = ngx.encode_base64(new_str)
    end
    -- 随机从 random_hex 中截取字符串
    local start = math.random(1, #random_hex - length + 1)
    return string.sub(random_hex, start, start + length - 1)
end