I’m trying to put randomly generated numbers/letters into one variable.
however, I have absolutely no idea how to do this (I’m not a good scripter lol)
here’s the code I’m using to generate the numbers:
also I have a table with all the other characters, to clarify what RANDOM_CHARACTERS is
local d1 = math.random(1, #RANDOM_CHARACTERS)
local d2 = math.random(1, #RANDOM_CHARACTERS)
local d3 = math.random(1, #RANDOM_CHARACTERS)
local d4 = math.random(1, #RANDOM_CHARACTERS)
local d5 = math.random(1, #RANDOM_CHARACTERS)
local d6 = math.random(1, #RANDOM_CHARACTERS)
local d7 = math.random(1, #RANDOM_CHARACTERS)
local d8 = math.random(1, #RANDOM_CHARACTERS)
local d9 = math.random(1, #RANDOM_CHARACTERS)
local d10 = math.random(1, #RANDOM_CHARACTERS)
local d11 = math.random(1, #RANDOM_CHARACTERS)
local d12 = math.random(1, #RANDOM_CHARACTERS)
To expand on this, and sorry for my lack of understanding, are you trying to create a variety of random letters to merge into one large string, potentially forming a word?
You can make a new table that holds all the values of these, and then a for-loop to insert them one by one:
local RandomCharacters = {}
-- Declaring a for-loop like this can make it iterate from 1 to 10
for Count = 1, 10 do
local char_index = math.random(1, #RANDOM_CHARACTERS)
local char = RANDOM_CHARACTERS[char_index]
table.insert(RandomCharacters[Count], char)
end
You can utilize table.concat to combine these values, like this:
local RandomizedText = table.concat(RandomCharacters, "")
This also works fine, in what you’re doing. But if you don’t want to write all those out, you can use tables:
Dragon_Trance got to this before me so ignore this reply.
A cleaner solution overall might be
local passCode = {}
for char = 1, 12 do
table.insert (passCode, Random.new():NextInteger (1, #RANDOM_CHARACTERS)
end
passCode = table.concat (passCode)