lua生成一组随机字符串

http://jingyan.baidu.com/article/b7001fe190ebf90e7382dd45.html

function random(n, m)
    math.randomseed(os.clock()*math.random(1000000,90000000)+math.random(1000000,90000000))
    return math.random(n, m)
end

function randomNumber(len)
    local rt = ""
    for i=1,len,1 do
        if i == 1 then
            rt = rt..random(1,9)
        else
            rt = rt..random(0,9)
        end
    end
    return rt
end

function randomLetter(len)
    local rt = ""
    for i = 1, len, 1 do
        rt = rt..string.char(random(97,122))
    end
    return rt
end
for i = 1, 5 do
    print(randomLetter(7))
end

你可能感兴趣的:(lua生成一组随机字符串)