diff --git a/src/common/tpt-rand.cpp b/src/common/tpt-rand.cpp index 5a076d8c7..84af99189 100644 --- a/src/common/tpt-rand.cpp +++ b/src/common/tpt-rand.cpp @@ -35,7 +35,7 @@ unsigned int RNG::operator()() int RNG::between(int lower, int upper) { unsigned int r = next(); - return static_cast(r % (upper - lower + 1)) + lower; + return static_cast(r % ((unsigned int)(upper) - (unsigned int)(lower) + 1U)) + lower; } bool RNG::chance(int nominator, unsigned int denominator) diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 5e991553c..7c4e75274 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -200,7 +200,7 @@ static int mathRandom(lua_State *l) { luaL_error(l, "interval is empty"); } - if (upper - lower + 1) + if ((unsigned int)(upper) - (unsigned int)(lower) + 1U) { lua_pushinteger(l, rng.between(lower, upper)); }