How would I randomize functions?
function a() end function b() end function c() end
How to randomize order in which they fire? Could I use math.random() for it?
There's a nice short, general solution that takes advantage of a simpler idea: selecting things from a list.
Functions are values, so we can make a list of functions and then select a random thing from that list:
local myFuns = {a, b, c} local myFun = myFuns[ math.random(1, #myFuns) ] myFun() -- Call the one we picked
You could check what math.random()
equals and call the function based on that;
function a() print("a") end function b() print("b") end function c() print("c") end while true do wait(2) local random = math.random(1,3) if random == 1 then a() elseif random == 2 then b() else c() end end
Although functional, this gets messy very very quickly if you have lots of functions.
I'm interested to see if anyone else has a better method.