From 133f624cc530a210c82d38e6e5ecf2cd732011b7 Mon Sep 17 00:00:00 2001 From: Oliver Kiehl Date: Sun, 1 Dec 2002 14:57:50 +0000 Subject: moved RNG to common/util.cpp svn-id: r5778 --- common/util.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'common/util.cpp') diff --git a/common/util.cpp b/common/util.cpp index cea9d3a8f0..2423cd0af0 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -157,3 +157,27 @@ int resStrLen(const char *src) } return num; } + +RandomSource::RandomSource(uint32 seed) +{ + _randSeed = seed; +} + +void RandomSource::setSeed(uint32 seed) +{ + _randSeed = seed; +} + +uint RandomSource::getRandomNumber(uint max) +{ + /* TODO: my own random number generator */ + _randSeed = 0xDEADBF03 * (_randSeed + 1); + _randSeed = (_randSeed >> 13) | (_randSeed << 19); + return _randSeed % (max + 1); +} + +uint RandomSource::getRandomNumberRng(uint min, uint max) +{ + return getRandomNumber(max - min) + min; +} + -- cgit v1.2.3