// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; namespace E { public class Util { private static Random rng = new Random(); public static T[] Shuffle(T[] a) { T[] a2 = (T[])a.Clone(); int[] b = new int[a.Length]; for(int i = 0; i < b.Length; i++) b[i] = rng.Next(); Array.Sort(b, a2); return a2; } public static ICollection Shuffle(ICollection c) { T[] a = new T[c.Count]; c.CopyTo(a, 0); return new List(Shuffle(a)); } } public class Program { public static void Main(string[] args) { List lst = new List(); lst.Add("A"); lst.Add("B"); lst.Add("C"); lst.Add("D"); lst.Add("E"); foreach(string s in lst) { Console.WriteLine(s); } ICollection c = Util.Shuffle(lst); foreach(string s in c) { Console.WriteLine(s); } } } }