Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to generate a random string of numbers letters and symbols?

I know I can generate a string of random numbers, but is it possible to gernerate a random string of letters and symbols and numbers? And if so, how would I do that?

2 comments

0

string.char is a possibility

0

maybe you can make a table with all the characters you want, and set the index value to random

1 answer

✓ Accepted answer

Create your own.

local upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local lowerCase = "abcdefghijklmnopqrstuvwxyz"
local numbers = "0123456789"
local symbols = "!@#$%&()*+-,./\:;<=>?^[]{}"

local characterSet = upperCase .. lowerCase .. numbers .. symbols

local keyLength = 32
local output = ""

for	i = 1, keyLength do
	local rand = math.random(#characterSet)
	output = output .. string.sub(characterSet, rand, rand)
end

print(output)
--Output: nz28IJ..=uPBF}6xeVhOQ7J,LR)CGF46
--Output: 4h<UH%!l.21,;LbG$S2:Ss!Vl>ks{IRJ

Keeping each set separate (lower case, upper case, numbers, etc) makes it easy to dynamically select what sets you want to use. The loop simply runs and selects a random character position and appends it to the final string.

Do note that the quotes, single and double, are left out. You can use the delimiter to add those back in, just be sure to compensate for the length and check for the character(s).

This discussion is preserved as it was. New answers, comments, and votes are closed.