src/AnvilPacker/Util/CollectionExtensions.cs
/// <summary> Shuffles the list elements using a custom RNG. </summary>
/// <param name="rng">A delegate in the form `int rng(int max)` which generates random numbers in the range [0..max) </param>
Shuffles the list elements using a custom RNG.
Shuffles the list elements using a custom RNG .
public static void Shuffle<T>(this List<T> list, Func<int, int> rng)
        {
            for (int i = list.Count - 1; i > 0; i--) {
                int j = rng(i + 1);
                T tmp = list[i];
                list[i] = list[j];
                list[j] = tmp;
            }
        }
public static void Shuffle < T > ( this List < T > list , Func < int , int > rng ) { for ( int i = list . Count - 1 ; i > 0 ; i -- ) { int j = rng ( i + 1 ) ; T tmp = list [ i ] ; list [ i ] = list [ j ] ; list [ j ] = tmp ; } }
Shuffles the list elements using a custom RNG.
Shuffles the list elements using a custom RNG .
List<T>
this
rng
Func<int, int>
A delegate in the form `int rng(int max)` which generates random numbers in the range [0..max)
A delegate in the form ` int rng ( int max ) ` which generates random numbers in the range [ 0 .. max )