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

Z Nonsensopedii, polskiej encyklopedii humoru
M
M (paaanie idź pan w ch)
Linia 1: Linia 1:
local p = {}
local p = {}

local function shuffleArr(t)
local n = #t
while n > 1 do
local k = math.random(n)
t[n], t[k] = t[k], t[n]
n = n - 1
end
return t
end


function p.shuffle(frame)
function p.shuffle(frame)
local t = shuffleArr(frame:getParent().args)
local t = frame:getParent().args
local s = ""
local s = ""
local n = #t
for _,arg in pairs(t) do
while n > 1 do
local k = math.random(n)
s = s .. arg .. "\n"
s = s .. table.remove(t, k) .. "\n"
n = n - 1
end
end

Wersja z 23:50, 11 maj 2019


local p = {}

function p.shuffle(frame)
	local t = frame:getParent().args
	local s = ""
	local n = #t
	while n > 1 do
    	local k = math.random(n)
    	s = s .. table.remove(t, k) .. "\n"
    	n = n - 1
	end
	
    return s   
end

return p