using System.Collections.Generic; namespace HeuristicLab.Problems.ProgramSynthesis.Push.Extensions { using HeuristicLab.Core; using HeuristicLab.Random; public static class CollectionExtensions { public static T Random(this IReadOnlyList source, IRandom random = null) { random = random ?? new MersenneTwister(); var x = random.Next(source.Count); return source[x]; } public static int HashCode(this IReadOnlyList source) { var hash = 19 * 31 + typeof(T).FullName.GetHashCode(); for (var i = 0; i < source.Count; i++) hash = hash * 31 + source[i].GetHashCode(); return hash; } public static int HashCode(this IEnumerable source) { var hash = 19 * 31 + typeof(T).FullName.GetHashCode(); foreach (var item in source) hash = hash * 31 + item.GetHashCode(); return hash; } } }