mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 07:34:35 +00:00
Fix shuffle to avoid bias
There's a subtle trick in shuffling: you should draw only from the part of the deck you have not seen! Otherwise, some permutations are more common than others.
This commit is contained in:
parent
2d06ec7b9c
commit
2846de2ea3
@ -173,7 +173,7 @@ end
|
||||
--shuffle the order of a table
|
||||
function tablex.shuffle(t, r)
|
||||
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]
|
||||
end
|
||||
return t
|
||||
|
Loading…
Reference in New Issue
Block a user