From 355fb26a3d304372d1ca916debcd86cde98fc5b9 Mon Sep 17 00:00:00 2001 From: Kortan Date: Sat, 4 May 2024 22:33:35 +0800 Subject: [PATCH] Make random apply seed using time (#37) --- lua/org-roam/core/utils/random.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/org-roam/core/utils/random.lua b/lua/org-roam/core/utils/random.lua index 5c7bea8..6a0e82f 100644 --- a/lua/org-roam/core/utils/random.lua +++ b/lua/org-roam/core/utils/random.lua @@ -6,11 +6,17 @@ ---@class org-roam.core.utils.Random local M = {} +local seeded = false ---@param m integer ---@param n integer ---@return integer function M.random(m, n) + if seeded == false then + -- https://www.lua-users.org/wiki/MathLibraryTutorial + math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) + seeded = true + end return math.random(m, n) end