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

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

local function shuffleArr(t)
math.randomseed(os.time())
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 = frame:getParent().args
local t = shuffleArr(frame:getParent().args)
local s = ""
local s = ""
local n = #t
while n > 1 do
for _,arg in pairs(t) do
s = s .. arg .. "\n"
local k = math.random(n)
s = s .. table.remove(t, k) .. "\n"
n = n - 1
end
end

Wersja z 23:55, 11 maj 2019


local p = {}

local function shuffleArr(t)
  math.randomseed(os.time())
  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)
	local t = shuffleArr(frame:getParent().args)
	local s = ""
	
	for _,arg in pairs(t) do
		s = s .. arg .. "\n"
	end
	
    return s   
end

return p