Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.