Random Letters

Hi,

I’m new to developing, and just want to know how to generate and display a random letter.

Also, generating and displaying a random string of characters of a specific length.

Thanks! [import]uid: 175394 topic_id: 30606 reply_id: 330606[/import]

How about this…

local letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" local pos = math.random(1, 26) local oneLetter= string.sub(letters, pos, pos) [import]uid: 114363 topic_id: 30606 reply_id: 122628[/import]

or to expand on that:

local letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"  
local maxLength = 10  
local pos  
local str = ""  
for i = 1, maxLength do  
 pos = math.random(26) -- if you only specify one number, it assumes 1 to n  
 str = str .. string.sub(letters, pos, pos)  
end  
print(str)  

[import]uid: 19626 topic_id: 30606 reply_id: 122639[/import]

How about this…

local letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" local pos = math.random(1, 26) local oneLetter= string.sub(letters, pos, pos) [import]uid: 114363 topic_id: 30606 reply_id: 122628[/import]

or to expand on that:

local letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"  
local maxLength = 10  
local pos  
local str = ""  
for i = 1, maxLength do  
 pos = math.random(26) -- if you only specify one number, it assumes 1 to n  
 str = str .. string.sub(letters, pos, pos)  
end  
print(str)  

[import]uid: 19626 topic_id: 30606 reply_id: 122639[/import]