Aimarekin
(Aimarekin)
June 17, 2020, 1:45pm
13
Do a Fisher-Yates shuffle, like this one:
local rng = Random.new()
function shuffle<V>(source: { V }):{ V }
for i = #source, 2, -1 do
local j = rng:NextInteger(1, i)
source[i], source[j] = source[j], source[i]
end
return source
end
The Fisher–Yates shuffle is an algorithm for shuffling a finite sequence. The algorithm takes a list of all the elements of the sequence, and continually determines the next element in the shuffled sequence by randomly drawing an element from the list until no elements remain. The algorithm produces an unbiased permutation: every permutation is equally likely. The modern version of the algorithm takes time proportional to the number of items being shuffled and shuffles them in place.
The Fisher...
57 Likes