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:
DUznanski 2021-05-20 12:33:52 -07:00 committed by GitHub
parent 2d06ec7b9c
commit 2846de2ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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