How do I merge strings from tables into one entire string?

I’m trying to make a 2FA system to make sure people can do certain stuff if they have the right requirements, that is if they have a certain code. I’m trying to make it so that the 2FA codes are completely random and making it as secure as possible. Around 33,554,431 possibilities according to google (keep in mind that 33,554,431 possibilities is only combinations of numbers, whilst mine is numbers and some letters in the alphabet aswell as 2 special characters) I just need to know how to merge strings from tables into one entire text.

Here’s what I’m trying to do

Here’s my script:

Module Script btw

--// 2-FA \\--

local DIGITS = 25 -- MAX: 25, MINIMUM = 5
local RANDOMIZE_TYPE = "Alphabets and Numbers" -- Types: "Numbers", "Alphabets", "Alphabets and Numbers"
local randoms = {"a", "b", "y", "i", "l", "p", "m", "x", "z", "f", "c", "e", "q", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", "?"}
local currentCode = ""

function randomize()
	local Outcome = {}
	if DIGITS <= 25 and DIGITS >= 5 then
		if RANDOMIZE_TYPE == "Alphabets and Numbers" then
			for index = 1, DIGITS do
				local random = math.random(1, DIGITS)
				local randomcap = math.random(1, 2)
				if randomcap == 2 then
					table.insert(Outcome, string.upper(randoms[random]))
					table.insert(Outcome, randoms[random])
	for i, v in pairs(Outcome) do

Could you do some thing like this?

for i, v in pairs(Outcome) do
local OutcomeString = ""..v

EDIT: Actually, don’t define the String in that, define it outside of the loop

For sure, I’ll try that real quick.

Thanks, that worked, although I had to do a little bit of changes to get it working. Thank you so much.

1 Like

Just out of curiosity, how did you make it work? I’m asking because I might be making like a code licensing system in the future.

Basically, a math.random(1, RANGE) always return the numbers from 1 to RANGE (lets say range = 25) the result will always return as a number 1 to 25, lets say “5” is the random result, then searches the “randoms” table for the fifth index then repeats this process till the for loop ends. I’m really bad at explaining lol.

Oh, so basically it loops through all the values in the table and adds them to the string in a random order? That’s a smart idea.

1 Like