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

How do I generate random hexadecimal numbers for characters?

I want to generate a random character by using hexadecimal codes (\65-90). However, whenever I use "", Roblox says everything after is an unfinished string. If I use "\" + (lets say) 65, then it prints "\65" instead of "A". I use the second backslash to fix the error.

I'd rather not create a table with all the letters and iterate through because I find this to be more useful, given it's possible.

-- Here's what I have so far
-- This is broken because of the single backslash

local Code = {}
for i = 1, 10 do
	table.insert(Code, "\" ..tostring(math.random(65, 90)))
	print(Code[i])
end

Any pointers would be greatly appreciated, thank you!

1 answer

✓ Accepted answer

So from investigating with the lua interpreter a bit, I'm not sure that you can concatenate a string escape sequence in a lua string. Luckily there is a workaround for converting from ASCII codes like you want into characters in string.char. Just to be specific about terminology, I don't believe that these characters are represented in hexadecimal because I could not find that language anywhere. Hexidecimal is the base 16 representation of numbers.

local Code = {}
for i = 1, 10 do
    table.insert(Code, string.char(math.random(65, 90)))
    print(Code[i])
end

1 comment

0

That right there is exactly what I needed! Thank you very much!

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