Optimal LINQ query to get a random sub collection – Shuffle
Further to mquander’s answer and Dan Blanchard’s comment, here’s a LINQ-friendly extension method that performs a Fisher-Yates-Durstenfeld shuffle: // take n random items from yourCollection var randomItems = yourCollection.Shuffle().Take(n); // … public static class EnumerableExtensions { public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) { return source.Shuffle(new Random()); } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random rng) … Read more