Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/script/scriptRandom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ static int lua_rngRandom(lua_State* L)
std::mt19937_64* rng = reinterpret_cast<std::mt19937_64*>(luaL_checkudata(L, 1, "RandomGenerator"));
auto fmin = luaL_checknumber(L, 2);
auto fmax = luaL_checknumber(L, 3);
if (fmin > fmax)
return luaL_error(L, "bad call random(%f, %f): lower bound is greater than upper bound", fmin, fmax);
lua_pushnumber(L, static_cast<lua_Number>(std::uniform_real_distribution<float>(fmin, fmax)(*rng)));
return 1;
}
Expand All @@ -23,6 +25,8 @@ static int lua_rngIRandom(lua_State* L)
std::mt19937_64* rng = reinterpret_cast<std::mt19937_64*>(luaL_checkudata(L, 1, "RandomGenerator"));
auto imin = luaL_checkinteger(L, 2);
auto imax = luaL_checkinteger(L, 3);
if (imin > imax)
return luaL_error(L, "bad call irandom(%d, %d): lower bound is greater than upper bound", imin, imax);
lua_pushinteger(L, std::uniform_int_distribution<>(imin, imax)(*rng));
return 1;
}
Expand Down
Loading