Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Knuth-shuffle/Lua/knuth-shuffle.lua
Normal file
13
Task/Knuth-shuffle/Lua/knuth-shuffle.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function table.shuffle(t)
|
||||
for n = #t, 1, -1 do
|
||||
local k = math.random(n)
|
||||
t[n], t[k] = t[k], t[n]
|
||||
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