I have a static table with 20+ records, I would like to select N (N<20) from that table in random manner. What is the best way to do it in the code with LINQ?
Here's the best way:
var randomUsers = users.OrderBy(x => Guid.NewGuid()).Take(15);
Maybe something like this would work:
int randomSkip;
int randomTake;
randomSkip = GenerateSomeAppropriateRandomNumber();
randomTake = GenerateSomeAppropriateRandomNumber();
resultSet = iEnumerable.Skip(randomSkip).Take(randomTake);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With