Taking random elements out of a collection using LINQ

2. March 2013 10:05 by martijn in

An elegant solution is so simple that something seems to be missing. I had that feeling when I found this solution of taking a random subset of a set of items:

 

 
 public static IEnumerable<T> TakeRandom<T>(this IEnumerable<T> list, int count) 
{
var shuffledList = list.OrderBy(l => Guid.NewGuid());
return shuffledList.Take(count);
}



szybka iphone 5/28/2015 3:28:36 AM United States #
szybka iphone

<p>I can’t determine how do I subscribe for your blog</p>

Francis Pettigrew 6/28/2015 12:25:38 PM United States #
Francis Pettigrew

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. A great read. I'll definitely be back.|

blog hog 7/11/2015 5:14:19 AM United States #
blog hog

For wordpress there is the wphone which works great for simple themes, how about joomla? any way of updating a joomla website via mobile?.

hindi song 7/15/2015 2:50:45 AM United States #
hindi song

... mp3 download & youtube downloader - Musica Cloud. XXXXXXXXXXXX XXXnXXXXXXX XXXXXXXX XnXX XXXXXXXX XXXXXXXnXXXXXXXX XXXXXXX.

one of a kind bikinis 7/29/2015 7:03:01 PM United States #
one of a kind bikinis

A person necessarily lend a hand to make seriously posts I'd state. This is the very first time I frequented your web page and so far? I amazed with the analysis you made to create this particular submit amazing. Wonderful task!

agau bendita trama 8/6/2015 1:16:23 AM United States #
agau bendita trama

I really appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You have made my day! Thanks again!