Skip to content

Commit

Permalink
Use better randomseed for Lua too
Browse files Browse the repository at this point in the history
see e985b7a

This solves a concrete issue with async workers generating the same
random numbers (as discovered in #14518).
  • Loading branch information
sfan5 committed Apr 6, 2024
1 parent ef0c194 commit f87994e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion builtin/init.lua
Expand Up @@ -26,7 +26,15 @@ do
core.print = nil -- don't pollute our namespace
end
end
math.randomseed(os.time())

do
-- Note that PUC Lua just calls srand() which is already initialized by C++,
-- but we don't want to rely on this implementation detail.
local seed = 1048576 * (os.time() % 1048576)
seed = seed + core.get_us_time() % 1048576
math.randomseed(seed)
end

minetest = core

-- Load other files
Expand Down

0 comments on commit f87994e

Please sign in to comment.