Skip to content

Instantly share code, notes, and snippets.

@philcook
Created March 12, 2018 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philcook/d81e02d9964c62b8a51b1787577f8f8c to your computer and use it in GitHub Desktop.
Save philcook/d81e02d9964c62b8a51b1787577f8f8c to your computer and use it in GitHub Desktop.
Percentage chance based on a roll of rand()
$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