This page is directors-only protected so that only directors can edit it.

Module:DidYouKnow: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
mNo edit summary
(this is only supposed to change every day anyways, according to the documentation, so the low resolution is not only not a problem, but not even low enough)
Line 5: Line 5:
local s = ""
local s = ""
local length = #facts.facts
local length = #facts.facts
math.randomseed(os.time())
math.randomseed(math.floor(os.time()/(60*60*24)))
--[[
os.time() only has second-level resolution, not millisecond-level, so we
may end up with the same seed sometimes
since all we're doing is picking random facts from a list, this isn't
a big deal
]]--
for i = 0, 4 do
for i = 0, 4 do

Revision as of 23:58, 16 December 2018

Implements {{DidYouKnow}}. All individual hooks are stored and can be added at Module:DidYouKnow/facts.

[view] [edit] [history] [refresh]The above documentation is transcluded from Module:DidYouKnow/doc.
local p = {}
local facts = require("Module:DidYouKnow/facts")

function p.getFacts()
	local s = ""
	local length = #facts.facts
	math.randomseed(math.floor(os.time()/(60*60*24)))
	
	for i = 0, 4 do
		s = s .. "* ... that " .. facts.facts[math.random(1, length)] .. "?"
		if i < 4 then s = s .. "\n" end
	end
	return s
end

-- List all facts. Intended to allow easier debugging.
function p.getAllFacts()
	local result = {}
	local length = #facts.facts
	
	for i = 1, length do
		result[i] = "* ... that " .. facts.facts[i] .. "?"
	end
	return table.concat(result, "\n")
end

return p