Przejdź do zawartości

Moduł:Random stub

Ze starnë Wikipedia

Moduł:Random stub/opis


local p = {}

local function getPages()
	return mw.loadData("Moduł:Random_stub/dane")
end

function p.list()
	local output = {}

	for _, page in ipairs(getPages()) do
		table.insert(output, "* [[" .. page .. "]]")
	end

	if #output == 0 then
		return "Nul danëch"
	end

	return table.concat(output, "\n")
end

function p.show()
	local pages = getPages()

	local count = 0
	for _ in pairs(pages) do
		count = count + 1
	end

	if count == 0 then
		return "Nul danëch"
	end

	math.randomseed(os.time())

	local result = {}
	local used = {}
	local amount = math.min(5, count)

	while #result < amount do
		local index = math.random(1, count)

		if not used[index] then
			used[index] = true
			table.insert(result, pages[index])
		end
	end

	local output = {}

	for _, page in ipairs(result) do
		table.insert(output, "* [[" .. page .. "]]")
	end

	return table.concat(output, "\n")
end

return p