How would I have a string with random letters?

Hi, So i am trying to make a script where I spits out random letters with a random amount.

So for Example, i would want it to say: eruyghujifuqwhdkjaswhdiuewafhdskzjvfgn,
So pretty much i want it to say gibberish (The Best Language)

How would I have a random letter and a random amount?
Would I need to create a Table of letters? Or, is there a function to do this?

Thanks.

1 Like

You could have a string of available characters, e.g.

local characters = "abcdefghijklmnopqrstuvwxyz"

You could also do a table but that’s a loooot of commas and quotes to type and it’s not really any better.

You could also abuse the fact that letters are all in a contiguous range in ASCII and use string.char or something, but that’s hacky and inflexible so probably don’t.

You can randomly pick a length n and then n times pick a random character from the set of available characters to append to a result.

Appending lots of times to get to a single result is bad™ though, so just add them to a list and use table.concat to turn a table of characters into a single string in one go.

1 Like
local t= {}
for i =1,math.random(1,maxletters),1 do
	table.insert(t,string.char(math.random(97,122)))
end
local randomstring = table.concat(t)

This script will create a string of random letters from a - z with a random length between 1 and maxletters

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.