diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/util.cpp | 6 | ||||
-rw-r--r-- | common/util.h | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/common/util.cpp b/common/util.cpp index 82a910f9a8..1f48a6ddd9 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -196,6 +196,12 @@ uint RandomSource::getRandomNumber(uint max) { return _randSeed % (max + 1); } +uint RandomSource::getRandomBit(void) { + _randSeed = 0xDEADBF03 * (_randSeed + 1); + _randSeed = (_randSeed >> 13) | (_randSeed << 19); + return _randSeed & 1; +} + uint RandomSource::getRandomNumberRng(uint min, uint max) { return getRandomNumber(max - min) + min; } diff --git a/common/util.h b/common/util.h index e7a71ff42c..dd205f159c 100644 --- a/common/util.h +++ b/common/util.h @@ -83,7 +83,7 @@ bool matchString(const char *str, const char *pat); class StringTokenizer { public: /** - * Creates a StringTokenizer. + * Creates a StringTokenizer. * @param str The string to be tokenized. * @param delimiters String containing all the delimiter characters (i.e. the characters to be ignored). * @note Uses space, horizontal tab, carriage return, newline, form feed and vertical tab as delimiters by default. @@ -132,6 +132,12 @@ public: */ uint getRandomNumber(uint max); /** + * Generates a random unsigned integer in the interval [0, 1]. + * Identical to getRandomNumber(1), but faster, hopefully. + * @return a random number in the interval [0, max]. + */ + uint getRandomBit(void); + /** * Generates a random unsigned integer in the interval [min, max]. * @param min the lower bound * @param max the upper bound |