i want something like this:
$chance = 40; //40%
if ( run the probability check script ) {
echo "event happened"; //do the event
}
else {
echo "event didn't happened";
}
what is the best solution to achieve something like that?
thanks a lot!
Use rand():
if (rand(1,100)<=$chance)
This will return a number between 1 and 100, so that the probability of it being lower or equal to 40 is 40%.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With