How to have random letters generate for usernames in a game

I am trying to make a tryout game but I want the username of players to be randomly generated letters, this is what I have so fair but would like feedback on it

length = 7
charset = {
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0" 
}
if length < 0 then 
    warn("You can only generate usernames with a minimum of 5 characters right now to prevent abuse!") 
else 
    found = false 
    local httpservice = game:GetService("HttpService") 
    while found == false do 
        gen = charset[math.random(1,#charset)] 
        for i = 1, length  - 1 do 
            gen = gen .. charset[math.random(1,#charset)] 
        end 
        print("Checking if name ''" .. gen .. "'' is taken via a proxy...") 
        result = httpservice:GetAsync("https://rprxy.xyz/UserCheck/DoesUsernameExist?username=" .. gen, true) 
        if result == '{"success":false}' then 
            untaken = gen 
            found = true 
        else 
            print("Username already taken! Name: " .. gen) 
        end
    end
    print("------------------------------------------------------------") 
    print("UNTAKEN USERNAME ALERT!") 
    warn("Username:") 
    print(untaken) 
    print("------------------------------------------------------------") 
end```
2 Likes

Can you use the code format?

3 of these ` with lua at the start and 3 of them at the end.

Makes it easier to read.

So I would suggest just using string.char(math.random(97,122)) since its just a function and easier to use, and in this case generating a random name would just be looping the function a couple times.

print(string.char(math.random(97,122)))   -- It will print a random letter

this one doesn’t account for the numbers in usernames though

hey use keyboard backtick

> ```
code
> ```

so that it is easy to read
local strTable = {}
for i = 97, 122 do
	strTable[i-97] = string.char(i)
end

for i = 48, 57 do
	strTable[i-22] = string.char(i)
end

function generateRandomUsername(length)
	local username = ''
	for i=1, length do username = username .. strTable[math.random(1,35)] end return username
end

This is what I would do…