randomize list order c# code example
Example 1: c# randomize a list
var shuffledcards = cards.OrderBy(a => Guid.NewGuid()).ToList();
Example 2: c# 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;
}
}