More languages
More actions
m (Alternative division) |
m (Testing a better random algorithm) |
||
Line 14: | Line 14: | ||
math.randomseed(rnd) | math.randomseed(rnd) | ||
while (rnd > b) do | while (rnd > b or rnd < a) do | ||
if (rnd > b) then | |||
local aux = b/2 | |||
rnd = math.floor(rnd/aux) | |||
elseif (rnd < a) then | |||
local aux = b/2 | |||
rnd = math.floor(rnd*aux) | |||
end | |||
end | end | ||
return rnd | return rnd | ||
end | end | ||
return p | return p |
Revision as of 02:20, 18 January 2023
local p = {}
function p.random(frame)
local parent = frame:getParent()
local a = tonumber(parent.args[1]) or 1
local b = tonumber(parent.args[2]) or 100
local Date = os.date()
local h = Date:match("(%d+):%d+:%d+")
local m = Date:match("%d+:(%d+):%d+")
local s = Date:match("%d+:%d+:(%d+)")
local rnd = s * s * math.random(1,b)
math.randomseed(rnd)
while (rnd > b or rnd < a) do
if (rnd > b) then
local aux = b/2
rnd = math.floor(rnd/aux)
elseif (rnd < a) then
local aux = b/2
rnd = math.floor(rnd*aux)
end
end
return rnd
end
return p