Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a script that has a 1 in 10 percent chance of printing somthing?

Asked by
Nidoxs 190
9 years ago
--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

1 answer

Log in to vote
2
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

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
Ad

Answer this question