I'm trying to make a randomized table that takes up less code space for organization.
Current code:
math.randomseed(tick())
local MyTable = {math.random(0, 100), math.random(0, 100), math.random(0, 100), math.random(0, 100)}
for i, v in ipairs(MyTable) do
print(i.."- "..v)
end
expected output:
1- some random number
2- a different random number
3- a different random number
4- a different random number
This does give me the output I want but the length of line 3 local MyTable = {...}
is annoying to deal with so I was wondering if there was a way I could assign a variable to give a random number and put that in place of each table index.
I already tested this btw:
math.randomseed(tick())
local rand = math.random(0, 100)
local MyTable = {rand, rand, rand, rand}
for i, v in ipairs(MyTable) do
print(i.."- "..v)
end
The issue with this is that because rand
is a pre-defined variable, it outputs the same number for each index.
If you have a solution it would be very helpful as I'm trying to work with 30 index long randomized tables and it is very difficult to go through. Thanks.