I was wondering if there is any way to generate random letters, kind of like math.random(1,5)
except for letters. Any help appreciated.
function doText(numLetters) local totTxt = "" for i = 1,numLetters do totTxt = totTxt..string.char(math.random(97,122)) end print(totTxt) end doText(12) -- Prints a string of a random 12 letters, this number can be changed; this is one of my outputs with 12: 'avbaajquwzgj'
If you're curious, 65 to 90 happens to be the alphabet capitalized, while 97 to 122 is lowercase.
local letters = {"a","b","c","d"} -- etc. local length = 5 local text = "" for i = 1,length do text = text.. "" ..letters[math.random(1,#letters)] if i == length then print(text) end end
This prints a 5 randomly generated letters.