An efficient way to randomize a list of maps or items

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
57 Likes