SHARE
TWEET

C# extension method for shuffling IList collections

ChestnutGames Aug 20th, 2015 186 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void Shuffle<T>(this IList<T> list)
  2. {
  3.         int n = list.Count;
  4.        
  5.         while (n > 1)
  6.         {
  7.                 n--;
  8.                 int k = Random.Range(0, n+1);
  9.                        
  10.                 T value = list[k];
  11.                 list[k] = list[n];
  12.                 list[n] = value;
  13.         }
  14. }
RAW Paste Data
Top