Jump to content

Module:Random and Module:Random/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
allow newline separators
 
Simplified code
 
Line 110: Line 110:
startTimestamp = '@' .. tostring(currentYearStartUnix) -- @ is used to denote Unix timestamps with lang:formatDate.
startTimestamp = '@' .. tostring(currentYearStartUnix) -- @ is used to denote Unix timestamps with lang:formatDate.
endTimestamp = '@' .. tostring(currentYearEndUnix)
endTimestamp = '@' .. tostring(currentYearEndUnix)
elseif t1 and not t2 then
elseif not t2 then
startTimestamp = '@0' -- the Unix epoch, 1 January 1970
startTimestamp = '@0' -- the Unix epoch, 1 January 1970
endTimestamp = t1
endTimestamp = t1
else
elseif t1 and t2 then
startTimestamp = t1
startTimestamp = t1
endTimestamp = t2
endTimestamp = t2
Line 264: Line 264:
-- This is because of the variability of os.clock (the time in seconds that the Lua script has been running for).
-- This is because of the variability of os.clock (the time in seconds that the Lua script has been running for).
math.randomseed(mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000))
math.randomseed(mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000))
elseif not cfg.lowTraffic then
-- Make the seed as random as possible without using anything time-based. This means that the same random number
-- will be generated for the same input from the same page - necessary behaviour for some wikicode templates that
-- assume bad pseudo-random-number generation.
local stats = mw.site.stats
local views = stats.views or 0 -- This is not always available, so we need a backup.
local seed = views + stats.pages + stats.articles + stats.files + stats.edits + stats.users + stats.activeUsers + stats.admins -- Make this as random as possible without using os.time() or os.clock()
math.randomseed(seed)
else
else
-- Make the random seed change every n seconds, where n is set by cfg.seedRefreshRate.
if not cfg.lowTraffic then
-- This is useful for low-traffic wikis where new edits may not happen very often.
-- Make the seed as random as possible without using anything time-based. This means that the same random number
math.randomseed(math.floor(os.time() / cfg.seedRefreshRate))
-- will be generated for the same input from the same page - necessary behaviour for some wikicode templates that
-- assume bad pseudo-random-number generation.
local stats = mw.site.stats
local views = stats.views or 0 -- This is not always available, so we need a backup.
local seed = views + stats.pages + stats.articles + stats.files + stats.edits + stats.users + stats.activeUsers + stats.admins -- Make this as random as possible without using os.time() or os.clock()
math.randomseed(seed)
else
-- Make the random seed change every n seconds, where n is set by cfg.seedRefreshRate.
-- This is useful for low-traffic wikis where new edits may not happen very often.
math.randomseed(math.floor(os.time() / cfg.seedRefreshRate))
end
end
if type(args) ~= 'table' then
error('the second argument to p.main must be a table')
end
end
assert(type(args) == 'table', 'the second argument to p.main must be a table')
return l[funcName](args, listType)
return l[funcName](args, listType)
end
end