summaryrefslogtreecommitdiff
path: root/src/core/random_func.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-04-17 11:49:25 +0000
committerfrosch <frosch@openttd.org>2010-04-17 11:49:25 +0000
commit184fa43df2e14c73162e641bc9bc83e403f069ed (patch)
treed24d525121ba0120bd172975ee2e0784035f7128 /src/core/random_func.cpp
parentcd20724d201b5b04c8dfac49b6b885ea988165ed (diff)
downloadopenttd-184fa43df2e14c73162e641bc9bc83e403f069ed.tar.xz
(svn r19652) -Fix: RandomRange() is used for bigger ranges in many cases, so generally extent it to handle 32 bits.
Diffstat (limited to 'src/core/random_func.cpp')
-rw-r--r--src/core/random_func.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/core/random_func.cpp b/src/core/random_func.cpp
index 588bcb7b2..1c53d99c7 100644
--- a/src/core/random_func.cpp
+++ b/src/core/random_func.cpp
@@ -24,9 +24,9 @@ uint32 Randomizer::Next()
return this->state[1] = ROR(s, 3) - 1;
}
-uint32 Randomizer::Next(uint16 max)
+uint32 Randomizer::Next(uint32 max)
{
- return GB(this->Next(), 0, 16) * max >> 16;
+ return ((uint64)this->Next() * (uint64)max) >> 32;
}
void Randomizer::SetSeed(uint32 seed)
@@ -55,9 +55,8 @@ uint32 DoRandom(int line, const char *file)
return _random.Next();
}
-uint DoRandomRange(uint max, int line, const char *file)
+uint32 DoRandomRange(uint32 max, int line, const char *file)
{
- assert(max <= UINT16_MAX);
- return GB(DoRandom(line, file), 0, 16) * max >> 16;
+ return ((uint64)DoRandom(line, file) * (uint64)max) >> 32;
}
#endif /* RANDOM_DEBUG */