Module:Random
Jump to navigation
Jump to search
local p = {}
function p.choose(frame)
local args = frame:getParent().args -- Fetch arguments correctly
local count = 0
local options = {}
-- Store arguments in a table and count them
for _, v in pairs(args) do
table.insert(options, v)
count = count + 1
end
-- Return an error message if no options are provided
if count == 0 then
return "No options provided!"
end
-- Seed the random generator for randomness
math.randomseed(os.time())
-- Pick a random option
local index = math.random(1, count)
return options[index] -- Return the chosen option
end
return p