You’d list all the indices of the dictionary inside of a separate table, then, get a random index from the newly created table.
--Example
local t = {} -- example dictionary
t.Key = "value"
t.AnotherKey = "anotherValue"
local function getRandomValue(tb)
local indices = {} -- a table that holds the indices in the provided table
for index in tb do -- loop through the provided table
table.insert(indices, index) -- insert the index into the table that holds the indices
end
return tb[indices[math.random(#indices)]]
-- returns a random index in tb using the indices table
--[[
the same as:
local randomIndex = indices[math.random(#indices)]
local value = tb[randomIndex]
--]]
end
print(getRandomValue(t)) -- prints a random value in the dictionary