Module:Randomize list
This module randomizes the order of a list; it accepts an unlimited amount of parameters (the list contents). Randomization will occur every time the page is re-parsed; purging can trigger this process.
Example usage
editCode
edit{{#invoke:Randomize list|main|apple|banana|cherry}}
Output
editbananacherryapple
TemplateData
editRandomizes the order of a list, accepting an unlimited amount of unnamed parameters (the list contents).
Parameter | Description | Type | Status | |
---|---|---|---|---|
Item 1 | 1 | First item of list
| Unknown | required |
Item 2 | 2 | Second item of list
| Unknown | required |
Item 3 | 3 | Third item of list
| Unknown | optional |
-- Randomizes the order of input parameters
-- By [[User:EpicPupper]]
local p = {}
function p.main(frame)
-- Get all the input strings from the template parameters
local inputs = {}
for i, v in ipairs(frame.args) do
table.insert(inputs, v)
end
-- Randomly shuffle the input strings
math.randomseed(os.time())
for i = #inputs, 2, -1 do
local j = math.random(i)
inputs[i], inputs[j] = inputs[j], inputs[i]
end
-- Generate the output string
local output = table.concat(inputs)
-- Return the output string
return output
end
return p