SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Random; | |
| 3 | using System.Collections; | |
| 4 | using System.Collections.Generic; | |
| 5 | ||
| 6 | ||
| 7 | public static class ListExtensions {
| |
| 8 | public static void Shuffle<T>(this IList<T> list) {
| |
| 9 | Random rnd = new Random(); | |
| 10 | for (var i = 0; i < list.Count; i++) | |
| 11 | list.Swap(i, rnd.Next(i, list.Count)); | |
| 12 | } | |
| 13 | ||
| 14 | public static void Swap<T>(this IList<T> list, int i, int j) {
| |
| 15 | var temp = list[i]; | |
| 16 | list[i] = list[j]; | |
| 17 | list[j] = temp; | |
| 18 | } | |
| 19 | } |