Created
March 12, 2018 11:52
-
-
Save philcook/d81e02d9964c62b8a51b1787577f8f8c to your computer and use it in GitHub Desktop.
Percentage chance based on a roll of rand()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$roll = rand(0,99); | |
$percentage_chance = 10; | |
// Override based on IP for testing | |
if (in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'))) { | |
$percentage_chance = 100; | |
} | |
if ($roll < $percentage_chance) { | |
echo 'Within 10% roll chance'; | |
} else { | |
echo 'Outside of roll chance'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment