Last active
July 28, 2018 19:27
-
-
Save mvenezia/1adc0d0ec6b031d03709e057990a26fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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