Is there any method to pick out answers from a dictionary randomly? Essentially, what I've been using a table such as this:
local tab = {
ID42 = {
-- other stuff
},
ID74 = {
-- other stuff
},
ID22 = {
-- other stuff
}
}
These IDs are given out numerically from 1 to somewhere in the thousands before the round resets the IDs and counter, but are deleted due to circumstances of manipulation during the round. These deletions have no patterns (ie; it's not the least recent ID or something since these IDs represent units in a game that are killed off in fights and other unpredictable events) so therefore I can't just use a math.random() for a set interval. I would love if someone could figure out a way to use math.random() to do this though.
I anticipate an answer such as this:
local tab = {obj = 5, obj2 = 7, obj3 = 9}
local newTab = {}
for _,v in pairs(tab) do
table.insert(newTab, v)
end
print(newTab[math.random(1,#newTab)])
HOWEVER, I do not want to convert my dictionary into an array of numerical indexes. Can anyone solve this without converting the dictionary? I'd really appreciate it.

1 comment
Oh, that's a good idea! It still seems like a pretty expensive call though, especially if you do it a lot, even without a table remake. I'll try to keep the calling minimal. It's better than the other version though, thanks!