From f87994edc7d698e5c159455ef50ef5070a925762 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 5 Apr 2024 15:34:52 +0200 Subject: [PATCH] Use better randomseed for Lua too see e985b7a0bf5ddf4999330a5a1a878654f68b254e This solves a concrete issue with async workers generating the same random numbers (as discovered in #14518). --- builtin/init.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/init.lua b/builtin/init.lua index cf4e8704e..49df70971 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -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