Skip to content

Instantly share code, notes, and snippets.

@hperrin
Last active August 29, 2018 20:50
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 hperrin/58c2cfcb065b84992644f1637bb997bb to your computer and use it in GitHub Desktop.
Save hperrin/58c2cfcb065b84992644f1637bb997bb to your computer and use it in GitHub Desktop.
// Returns true about 50% of the time, false about 50% of the time.
export default const maybe = () => Math.random() < .5;
// This should be closer to .5 the more iterations you run.
export const tester = iterations => {
let yes = 0;
for (let i = 0; i < iterations; i++) maybe() && yes++;
return yes/iterations;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment