using System; using System.Collections.Generic; namespace FSO.Client.Utils { public static class CollectionUtils { public static void Shuffle(this IList list) { Random rng = new Random(); int n = list.Count; while (n > 1) { n--; int k = rng.Next(n + 1); T value = list[k]; list[k] = list[n]; list[n] = value; } } public static IEnumerable Select(this Array items, Func converter) { var result = new List(); foreach (var item in items) { result.Add(converter((TSource)item)); } return result; } public static Dictionary Clone(Dictionary input) { var result = new Dictionary(); foreach (var val in input) { result.Add(val.Key, val.Value); } return result; } private static Random RAND = new Random(); public static T RandomItem(this T[] items) { var index = RAND.Next(items.Length); return items[index]; } } }