public static T SelectElementAtRandom <T>(this System.Collections.Generic.IList <T> container) where T : class { if (container.Count == 0) { return(null); } var randomizer = new Random(); var randomIndex = randomizer.Next(0, container.Count - 1); T randomElement = container.ElementAt(randomIndex); return(randomElement); }