Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Random;
- using System.Collections;
- using System.Collections.Generic;
- public static class ListExtensions {
- public static void Shuffle<T>(this IList<T> list) {
- Random rnd = new Random();
- for (var i = 0; i < list.Count; i++)
- list.Swap(i, rnd.Next(i, list.Count));
- }
- public static void Swap<T>(this IList<T> list, int i, int j) {
- var temp = list[i];
- list[i] = list[j];
- list[j] = temp;
- }
- }
Add Comment
Please, Sign In to add comment