Можно записать все в одну строку и потом посимвольно выдергивать
function randomPass(length)
length = length or 0
local output = ''
dic = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
while(length > 0) do
local randId = math.random(1,#dic)
output = output .. dic:sub(randId ,randId)
length = length - 1
end
return output
end