Skip to main content
This is excellent. However, I believe there is a typo tb -> keys. (I cannot comment properly because I do not yet have sufficient reputation.)
Source Link

I personally use the following function inspired by @ahmadh

function random_elem(tb)
    local keys = {}
    for k in pairs(tb) do table.insert(tbkeys, k) end
    return tb[keys[math.random(#keys)]]
end

I personally use the following function inspired by @ahmadh

function random_elem(tb)
    local keys = {}
    for k in pairs(tb) do table.insert(tb, k) end
    return tb[keys[math.random(#keys)]]
end

I personally use the following function inspired by @ahmadh

function random_elem(tb)
    local keys = {}
    for k in pairs(tb) do table.insert(keys, k) end
    return tb[keys[math.random(#keys)]]
end
Source Link
user9145571
user9145571

I personally use the following function inspired by @ahmadh

function random_elem(tb)
    local keys = {}
    for k in pairs(tb) do table.insert(tb, k) end
    return tb[keys[math.random(#keys)]]
end