Moduł:Shuffle: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
M
M
Linia 3: Linia 3:
function p.shuffle(frame)
function p.shuffle(frame)
math.randomseed(os.time())
math.randomseed(os.time())
local t = {}
for _,arg in pairs(frame:getParent().args) do
for _,arg in pairs(frame:getParent().args) do
table.insert(t, arg)
table.insert(t, arg)

Wersja z 00:07, 12 maj 2019


local p = {}

function p.shuffle(frame)
	math.randomseed(os.time())
	local t = {}
	for _,arg in pairs(frame:getParent().args) do
		table.insert(t, arg)
	end

	local s = ""
	while #t > 0 do
    	local k = math.random(#t)
    	s = s .. table.remove(t, k) .. "\n"
	end
	
    return s   
end

return p