Bonus system with a % chance?

Hello!
Thinking to create a game in php, well, yet think through and develop functionality.
There is a button bonus every 15 minutes, the user gets certain resources.
And wish that you had the chance like 1% more or whether any of the resource?
March 12th 20 at 08:08
1 answer
March 12th 20 at 08:10
Solution
if (rand(0, 99) == 1) {
 //Give the resource
}
But if I want 5% then rand(0, 20) == 1? - Howard commented on March 12th 20 at 08:13
@Howard,
<?php
$chance = 5; // chance in %

if (rand(0, 99) < $chance) {
 echo 'win'; 
}
- Henderson27 commented on March 12th 20 at 08:16
@Howard, just rand(0, 19) and do not necessarily == 1 we can take any number from the range. Or as posted by @Henderson27. - Daija_To commented on March 12th 20 at 08:19
@Daija_To, my version is more convenient :) - Henderson27 commented on March 12th 20 at 08:22
@Henderson27, Yes, I did argue? :) Just the idea gave, and the man himself tighten. :) - Daija_To commented on March 12th 20 at 08:25

Find more questions by tags Web DevelopmentPHP