Advertisement
Frank84

Extension Example

Oct 4th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public static class ListExtensions
  6. {
  7.     // From http://stackoverflow.com/questions/273313/randomize-a-listt-in-c
  8.     // Fisher-Yates shuffle
  9.     public static void Shuffle<T>(this IList<T> list)
  10.     {
  11.         System.Random rng = new System.Random();
  12.         int n = list.Count;
  13.         while (n > 1)
  14.         {
  15.             n--;
  16.             int k = rng.Next(n + 1);
  17.             T value = list[k];
  18.             list[k] = list[n];
  19.             list[n] = value;
  20.         }
  21.     }
  22. }
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement