I am writing an app using .NET, C#, LINQ to entities and SQL Server 2008.
I would like to pick a row randomly from a table. Is there a way to achieve this using the LINQ queries. One approach would be to get a list of rows from the table and then pick one of them randomly, which is very straight forward.
Just curious, if there is a way to include the randomness attribute in the LINQ.
Excuse the Pseudocode:
static IEnumerable<RowType> RandomRows()
{
while (true)
{
yield return GetRowByID((new Random).Next(NumberOfRowsInTable));
}
}
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