Skip to content

Instantly share code, notes, and snippets.

@mvenezia
Last active July 28, 2018 19:27
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 mvenezia/1adc0d0ec6b031d03709e057990a26fb to your computer and use it in GitHub Desktop.
Save mvenezia/1adc0d0ec6b031d03709e057990a26fb to your computer and use it in GitHub Desktop.
namespace VenzMisc
{
// Precondition: prob is between 0.0 and 1.0 inclusive.
// Returns: generates random probability between 0.0 and 1.0 and returns true if randomProb
// is <= prob, else false. Each invocation of this function has a (prob*100.0) percent chance
// of returning true.
bool Probability(float prob)
{
float randomProb = (RAND_MAX - rand()) / static_cast<float>(RAND_MAX);
return (randomProb <= prob) ? true : false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment