Alex Rivera | Logout

Optimal LINQ query to get a random sub collection - Shuffle

Asked 2009-10-30T18:44:41.510
47

Please suggest an easiest way to get a random shuffled collection of count 'n' from a collection having 'N' items. where n <= N

Edit
Report

1 Answer

-3

Sorry for ugly code :-), but


var result =yourCollection.OrderBy(p => (p.GetHashCode().ToString() + Guid.NewGuid().ToString()).GetHashCode()).Take(n);

answered 2009-10-31T13:39:41.197

Your Answer