Module:Random: Difference between revisions

From MuttWiki
Jump to navigationJump to search
testing
 
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


function p.test(frame)
local function setseed()
return "This is a test!"
math.randomseed(math.floor(os.time() / 3600))
end
 
function p.num(frame)
setseed()
if #frame.args == 0 then
return math.random()
elseif #frame.args == 1 then
return math.random(tonumber(frame.args[1]))
elseif #frame.args >= 2 then
local _min = tonumber(frame.args[1])
local _max = tonumber(frame.args[2])
end
if _min > _max then
_min, _max = _max, _min
end
end
 
function p.pick(frame)
setseed()
return frame.args[math.random(#frame.args)]
end
end


return p
return p

Revision as of 04:23, 22 February 2025

Documentation for this module may be created at Module:Random/doc

local p = {}

local function setseed()
	math.randomseed(math.floor(os.time() / 3600))
end

function p.num(frame)
	setseed()
	if #frame.args == 0 then
		return math.random()
	elseif #frame.args == 1 then
		return math.random(tonumber(frame.args[1]))
	elseif #frame.args >= 2 then
		local _min = tonumber(frame.args[1])
		local _max = tonumber(frame.args[2])
	end
	if _min > _max then
		_min, _max = _max, _min
	end
end

function p.pick(frame)
	setseed()
	return frame.args[math.random(#frame.args)]
end

return p