Created
January 23, 2014 13:00
-
-
Save lacolaco/8578113 to your computer and use it in GitHub Desktop.
IE<T>#Random() impletation
This file contains hidden or 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
static Random _Rand = new Random(); | |
static T RandomOrderBy<T>(IEnumerable<T> ie) | |
{ | |
return ie.OrderBy(x => _Rand.Next()).First(); | |
} | |
static T RandomElementAt<T>(IEnumerable<T> ie) | |
{ | |
return ie.ElementAt(_Rand.Next(ie.Count())); | |
} | |
static T RandomSkip<T>(IEnumerable<T> ie) | |
{ | |
return ie.Skip(_Rand.Next(ie.Count())).First(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment