Get random element from a List
using System; using System.Collections.Generic; namespace TradeHelp.Utilities { /// <summary> /// /// </summary> public static class RandomHelper { private static readonly Random _random = new Random(DateTime.Now.Millisecond); /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list"></param> /// <returns></returns> public static T GetRandom<T>(this IList<T> list) { return list[_random.Next(0, list.Count)]; } } }