aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorOliver Kiehl2002-12-01 14:57:50 +0000
committerOliver Kiehl2002-12-01 14:57:50 +0000
commit133f624cc530a210c82d38e6e5ecf2cd732011b7 (patch)
tree94809a1086a54ed4929606a4d6e879806ea0d6b5 /common
parent89eaf9b319299950872229e585dca30e2995772f (diff)
downloadscummvm-rg350-133f624cc530a210c82d38e6e5ecf2cd732011b7.tar.gz
scummvm-rg350-133f624cc530a210c82d38e6e5ecf2cd732011b7.tar.bz2
scummvm-rg350-133f624cc530a210c82d38e6e5ecf2cd732011b7.zip
moved RNG to common/util.cpp
svn-id: r5778
Diffstat (limited to 'common')
-rw-r--r--common/util.cpp24
-rw-r--r--common/util.h12
2 files changed, 36 insertions, 0 deletions
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;
+}
+
diff --git a/common/util.h b/common/util.h
index 37576bd8af..a5e13c0e4f 100644
--- a/common/util.h
+++ b/common/util.h
@@ -72,4 +72,16 @@ void hexdump(const byte * data, int len);
// Resource string length
int resStrLen(const char *src);
+
+class RandomSource {
+private:
+ uint32 _randSeed;
+
+public:
+ RandomSource(uint32 seed = 0xA943DE33);
+ void setSeed(uint32 seed);
+ uint getRandomNumber(uint max);
+ uint getRandomNumberRng(uint min, uint max);
+};
+
#endif