GE Lua Documentation

Press F to search!

tableChooseRandomKey

Definition


-- @/lua/ge/ge_utils.lua:1485
function tableChooseRandomKey(t)
  if t == nil then return nil end
  if not __randomWasSeeded then
    math.randomseed(os.time())
    __randomWasSeeded = true
  end
  local randval = math.random(1, tableSize(t))
  local n = 0
  for k, v in pairs(t) do
    n = n + 1
    if n == randval then
      return k
    end
  end
  return nil
end

Callers