fix(uuid): resolve duplicate UUID generation by improving random seeding (#1473)

- Moved math.randomseed() from the generation function to the initialization phase.
- Replaced os.time() with a more precise seed (os.time + os.clock) to prevent identical sequences when calls occur within the same second.
This commit is contained in:
Yuri Sequoia
2026-02-04 18:42:18 +08:00
committed by GitHub
parent 05f040d700
commit 739a87af0a

View File

@@ -33,12 +33,12 @@ end
local M = {} local M = {}
function M.init(env) function M.init(env)
randomseed(os.time() + os.clock() * 1000)
M.uuid = env.engine.schema.config:get_string(env.name_space:gsub("^*", "")) or "uuid" M.uuid = env.engine.schema.config:get_string(env.name_space:gsub("^*", "")) or "uuid"
end end
function M.func(input, seg, _) function M.func(input, seg, _)
if input == M.uuid then if input == M.uuid then
randomseed(os.time())
yield_cand(seg, generate_uuid_v4()) yield_cand(seg, generate_uuid_v4())
end end
end end