Skip to content

Instantly share code, notes, and snippets.

@BenBestmann
Last active July 1, 2016 14:22
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 BenBestmann/56bd2fbf960e83a32d3cea7219eca85c to your computer and use it in GitHub Desktop.
Save BenBestmann/56bd2fbf960e83a32d3cea7219eca85c to your computer and use it in GitHub Desktop.
Let some event happen by a given probability. Will return true or false given a certain probability in percent (1-99).
function takeChance(probability) {
probability = probability / 100;
return !!probability && Math.random() <= probability;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment