Skip to content

Instantly share code, notes, and snippets.

@haggen
Last active February 21, 2024 04:16
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save haggen/2fd643ea9a261fea2094 to your computer and use it in GitHub Desktop.
Save haggen/2fd643ea9a261fea2094 to your computer and use it in GitHub Desktop.
Random strings in Lua
math.randomseed(os.time())
local charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
function string.random(length)
if length > 0 then
return string.random(length - 1) .. charset:sub(math.random(1, #charset), 1)
else
return ""
end
end
@wavesk
Copy link

wavesk commented Jul 31, 2023

abc = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","z","y","w","q","1","2","3","4","5","6","7","8","9","0"}
local string = ""
function GeneratedString() 
    for i=1,35 do
        rdm = math.random(1,35)
        string = string..abc[rdm]
    end
    return string
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment