mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 22:24:35 +00:00
Merge pull request #22 from DUznanski/shuffle-fix
Fix shuffle to avoid bias
This commit is contained in:
commit
c1a4e6898a
@ -173,7 +173,7 @@ end
|
|||||||
--shuffle the order of a table
|
--shuffle the order of a table
|
||||||
function tablex.shuffle(t, r)
|
function tablex.shuffle(t, r)
|
||||||
for i = 1, #t do
|
for i = 1, #t do
|
||||||
local j = _random(1, #t, r)
|
local j = _random(i, #t, r)
|
||||||
t[i], t[j] = t[j], t[i]
|
t[i], t[j] = t[j], t[i]
|
||||||
end
|
end
|
||||||
return t
|
return t
|
||||||
|
Loading…
Reference in New Issue
Block a user