diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 10b6c0f25..5e991553c 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -200,7 +200,16 @@ static int mathRandom(lua_State *l) { luaL_error(l, "interval is empty"); } - lua_pushinteger(l, rng.between(lower, upper)); + if (upper - lower + 1) + { + lua_pushinteger(l, rng.between(lower, upper)); + } + else + { + // The interval is *so* not empty that its size overflows 32-bit integers + // (only possible if it's exactly 0x100000000); don't use between. + lua_pushinteger(l, int(rng())); + } return 1; }