Skip to content

Instantly share code, notes, and snippets.

@dreamyguy
Last active September 10, 2018 20:16
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 dreamyguy/4d9b6b920fbb2290a2fa258befe35dbc to your computer and use it in GitHub Desktop.
Save dreamyguy/4d9b6b920fbb2290a2fa258befe35dbc to your computer and use it in GitHub Desktop.
Chance + probability = possibility
// Calculate chance
const chance = (percentage) => {
const probability = (percentage / 100);
return (Math.random() < probability ? 1 : 0);
};
// Set percentage of possibility (10 = 10%, 75 = 75%)
const possibility = chance(70);
// Only execute it if 'possibility' is truthy
if (possibility) {
// It's possible!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment