Skip to content

Instantly share code, notes, and snippets.

@AlphaGit
Created April 16, 2012 14:33
Show Gist options
  • Save AlphaGit/2399155 to your computer and use it in GitHub Desktop.
Save AlphaGit/2399155 to your computer and use it in GitHub Desktop.
T IEnumerable<T>.RandomElement() extension method
internal static class IEnumerableExtensions
{
private static Random _random = new Random();
public static T RandomElement<T>(this IEnumerable<T> list)
{
var index = _random.Next(list.Count());
return list.ElementAt(index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment