// 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; namespace E { public class Util { private static Random rng = new Random(); public static ICollection Shuffle(ICollection c) { object[] a = new object[c.Count]; c.CopyTo(a, 0); byte[] b = new byte[a.Length]; rng.NextBytes(b); Array.Sort(b, a); return new ArrayList(a); } } public class Program { public static void Main(string[] args) { ArrayList lst = new ArrayList(); 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); } } } }