词条 | Module:Random TAFI |
释义 | local p = {} -- Named argument |list= used, like: {{#invoke:Random TAFI|choose|list=#item1 #item2 #item3}}function p.choose(frame) if mw.isSubsting() then math.randomseed(mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000)) -- Generates a different number every time the module is called, even from the same page. -- This is because of the variability of os.clock (the time in seconds that the Lua script has been running for).
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 else return "Error: Must be substituted – use {{subst:#invoke: ... }}" end end return p |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。