Answers for "array shuffler c#"

C#
3

c# list shuffle

var rnd = new Random();
var randomized = list.OrderBy(item => rnd.Next());
Posted by: Guest on July-22-2021
0

c# list shuffle

private static Random rng = new Random();  

public static void Shuffle<T>(this IList<T> list)  
{  
    int n = list.Count;  
    while (n > 1) {  
        n--;  
        int k = rng.Next(n + 1);  
        T value = list[k];  
        list[k] = list[n];  
        list[n] = value;  
    }  
}
Posted by: Guest on March-24-2022

C# Answers by Framework

Browse Popular Code Answers by Language