Skip to content

Instantly share code, notes, and snippets.

@cosinewaves
Created September 3, 2025 19:38
Show Gist options
  • Save cosinewaves/b747178c668b2f37821d6205060d569d to your computer and use it in GitHub Desktop.
Save cosinewaves/b747178c668b2f37821d6205060d569d to your computer and use it in GitHub Desktop.
returns a random element in table
--!strict
-- pick.luau
math.randomseed(os.clock())
return function<T>(list: { T }): T
assert(#list > 0, "tried to pick a element from an empty table")
return list[math.random(1, #list)] :: T
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment