random - Lua function selector -
i have 3 functions. when user presses 'e' key want select 1 of functions (at random), feel has math.random
can't figure out.
you don't use math.random
select function; use pick random number, can use index function need table (as 1 example):
local list = { function() print(1) end, function() print(2) end, function() print(3) end } math.randomseed(os.time()) -- don't forget seed or same sequence = 1, 10 list[math.random(#list)]() end
Comments
Post a Comment