Created
April 16, 2012 14:33
-
-
Save AlphaGit/2399155 to your computer and use it in GitHub Desktop.
T IEnumerable<T>.RandomElement() extension method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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