Improve biased shuffle of 27d1c32
John Smith

John Smith commited on 2022-295 15:08:15
Showing 1 changed files, with 2 additions and 1 deletions.


The review shuffle algorithm is now biased in favour of
more probable swaps towards the end of the review queue,
such that prompts desperately overdue will be almost certainly
reviewed soon, but lower-priority prompts can be
shuffled around extensively.
... ...
@@ -52,10 +52,11 @@ end
52 52
     shuffles a table in-place,
53 53
     intentionally biased to keep the list
54 54
     in a roughly-similar order to how it was originally
55
+    (but so that the list may deviate more towards the end)
55 56
 ]]
56 57
 local function biasedshuffle(t)
57 58
     for i = 1, (#t-1) do
58
-        if math.random() < 0.5 then
59
+        if math.random() < (i / #t)^0.5 then
59 60
             local s = t[i]
60 61
             t[i] = t[i + 1]
61 62
             t[i + 1] = s
62 63