new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
14
Task/Knuth-shuffle/Lua/knuth-shuffle.lua
Normal file
14
Task/Knuth-shuffle/Lua/knuth-shuffle.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function table.shuffle(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
|
||||
math.randomseed( os.time() )
|
||||
a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
table.shuffle(a)
|
||||
for i,v in ipairs(a) do print(i,v) end
|
||||
Loading…
Add table
Add a link
Reference in a new issue