Skip to content

Instantly share code, notes, and snippets.

@lacolaco
Created January 23, 2014 13:00
Show Gist options
  • Save lacolaco/8578113 to your computer and use it in GitHub Desktop.
Save lacolaco/8578113 to your computer and use it in GitHub Desktop.
IE<T>#Random() impletation
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