so lets say you have 4 options Option A Option B Option C Option D
Option A has a 50% chance of being selected, option B has a 30% chance of being selected, option C has a 10% chance of being selected, and option D also has a 10% chance of being selected
does anybody know I can do this when I call a function? like randomly select one of the four options at the given rates?
This should be quite easy using math.random()
. When I said that, you may have thought "That generates a whole number, not a value based on probability", but if you think outside of the box, it becomes very basic. All you would have to do is set a variable for math.random(1,10) like so:
local choice = math.random(1,10)
and tell the script that if it is 1, 2, 3, 4, or 5 (5/10 numbers aka 50%), do option A, if it is 2, 3, or 4, do option B (3/10 numbers aka 30%), etc, like so:
local choice = math.random(1,10) if choice == 1 or choice == 2 or choice == 3 or choice == 4 or choice == 5 then -- do option A elseif choice == 6 or choice == 7 or choice == 8 then -- do option B elseif choice == 9 then -- do option C elseif choice == 10 then -- do option D end
Hope this helped.
-Cmgtotalyawesome