Jump to content

Module:Choose random TAFI

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Evad37 (talk | contribs) at 02:38, 31 July 2015 (no need for dependency on Module:Random). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

-- Named argument |list= used, like: {{#invoke:Sandbox/Evad37/Random TAFI|choose|list=#[[item1]] #[[item2]] #[[item3]]}}

function p.choose(frame)
	local list = frame.args.list                       -- List of articles inputed via a single paramtere
	local articles = mw.text.split(list, '#')          -- Split list into an array of substrings (each containing an article). 
	local chosen = articles[math.random(2, #articles)] -- Note: First substring is empty as list begins with a #
	return mw.text.trim(chosen)                        -- Trim whitespace before returning
end

return p