PHP rate to chance for event to happen
问题 What I'm trying to do ( but getting totally confused with ) is to make a code in PHP that executes a code based on a chance that's given in decimal numbers (10 decimals max) where as 1 would be 100% chance for the code to be executed. Here's what I tried but is not working properly: <?php /* Rate to chance. */ //max 10 decimals $rate = '0.010000000000'; //<-- should equal 1% chance $chance = $rate*pow(10,10); $random = mt_rand(0,pow(10,10)); if($random < $chance) { echo "Ok."; //should be