From 2846de2ea39e04cd00ed9564e990bef27a270a98 Mon Sep 17 00:00:00 2001 From: DUznanski Date: Thu, 20 May 2021 12:33:52 -0700 Subject: [PATCH] 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. --- tablex.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tablex.lua b/tablex.lua index 8af5f35..acc7a85 100644 --- a/tablex.lua +++ b/tablex.lua @@ -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