Skip to content

Instantly share code, notes, and snippets.

@rameshbaskar
Last active October 24, 2021 13:44
Show Gist options
  • Save rameshbaskar/2507040c85932fa578a6924efaca35ff to your computer and use it in GitHub Desktop.
Save rameshbaskar/2507040c85932fa578a6924efaca35ff to your computer and use it in GitHub Desktop.
// a refValue of 0.5 will generate equal amount of true and false
// a refValue greater than 0.5 will generate more true values
// a refValue less than 0.5 will generate more false values
const randomBoolean = (positiveBias = false) => {
const refValue = positiveBias ? 0.8 : 0.5;
return Math.random() < refValue;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment