C# Shuffle

Date: 2023-01-13
public static IList<T> Shuffle<T>(IList<T> list)
{
    var provider = new RNGCryptoServiceProvider();
    int n = list.Count;
    while (n > 1)
    {
        byte[] box = new byte[1];
        do provider.GetBytes(box);
        while (!(box[0] < n * (Byte.MaxValue / n)));
        int k = (box[0] % n);
        n--;
        T value = list[k];
        list[k] = list[n];
        list[n] = value;
    }
    return list;
}
71990cookie-checkC# Shuffle