--How do I something that has a 1 in 10 percent chance of happening?
for i = math.random(1,10)?
print("I am a rare print.")
end
✓ ANSWER ACCEPTED
How do I make a script that has a 1 in 10 percent chance of printing somthing?
1 answer
✓ Accepted answer
You would have to use an if statement to ensure that it only prints once out of the ten possible times. Aside from that, you should indeed be using (1,10), as 1 is a tenth on 10.
local chance = math.random(1,10)
-- execute if 1
local success = function()
print('success')
end
--execute if not 1
local failure = function()
print('failure')
end
if chance == 1 then --10%
success()
else -- other 90%
failure()
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
