DMeville

Untitled

May 21st, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public static class ListExtensions  {
  7.     public static void Shuffle<T>(this IList<T> list, Random rnd) {
  8.         for (var i = 0; i < list.Count; i++)
  9.             list.Swap(i, rnd.Next(i, list.Count));
  10.     }
  11.  
  12.     public static void Swap<T>(this IList<T> list, int i, int j) {
  13.         var temp = list[i];
  14.         list[i] = list[j];
  15.         list[j] = temp;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment