Module:Random

--- Module for randomizing various article contents (within reason) not already -- covered by --  Extension:RandomSelection & Extension:RandomImage -- @module             random -- @alias              _rand -- @author             *User:Deakula -- @release            beta local _rand = {}

--- Accepts 1-100 pieces of content to randomize in Tabber tabs. -- -- @function           rand.randomizeTabber -- @param              {table} f The calling frame. -- -- @error[36]          {string} More than the limit of 100 tab options provided -- @error[45]          {string} No tab options provided -- @return             {string} The parser function version of Tabber with randomized tabs. function _rand.randomizeTabber(f) -- Table that stores pieces of the final Tabber content string. local outputTabs = {} -- Iterator for loop. local i = 0 -- Seed math.random with the sum of total wiki edits, total wiki pages, -- current os.time, and floor of os.clock * 1,000,000,000. math.randomseed( mw.site.stats.edits + mw.site.stats.pages + os.time + math.floor(os.clock * 1000000000)) -- Purge first random number result by calling math.random. math.random -- Loop through the template args which should be content intended to be --	paginated into Tabber tabs. for k, v in pairs(f:getParent.args) do -- Iterate the iterator. i = i+1 -- Throw an error if ore than 100 tab options were provided. if i > 100 then error("More than the limit of 100 tab options provided") end -- Insert the current tab content into outputTabs in a random position -- between 1 and i (inclusive). table.insert( outputTabs, math.random( i ), k .. '=' .. v .. "|-|" ) end -- Throw an error if no tabs were provided. if i == 0 then error("No tab options provided") end -- Trim "|-|" off the end of the last tab in outputTabs. outputTabs[ i ] = string.sub( outputTabs[ i ], 1, -4 ) -- Call the Tabber parser function with the template's frame, concatenate -- outputTabs into a string, and provide that string as the Tabber's args. return f:callParserFunction{ name="#tag:tabber", args=table.concat( outputTabs ) } end

return _rand