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.
1 | function doText(numLetters) |
2 | local totTxt = "" |
3 | for i = 1 ,numLetters do |
4 | totTxt = totTxt..string.char(math.random( 97 , 122 )) |
5 | end |
6 | print (totTxt) |
7 | end |
8 |
9 | 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.
01 | local letters = { "a" , "b" , "c" , "d" } -- etc. |
02 | local length = 5 |
03 | local text = "" |
04 |
05 | for i = 1 ,length do |
06 | text = text.. "" ..letters [ math.random( 1 ,#letters) ] |
07 | if i = = length then |
08 | print (text) |
09 | end |
10 | end |
This prints a 5 randomly generated letters.