As the title says, what’s the most efficient way to get a random selection of x DataRows from a DataTable.
Would it be to iteratively do something like the following until I have as many as I need?
protected DataRow SelectRandomRow(DataTable dataTable, Random randomSelector)
{
return dataTable.Rows[randomSelector.Next(dataTable.Rows.Count)];
}
There must be a better way..?
Your solution seems like a perfectly reasonable option.
You’ll probably want to add a check for duplicate rows being returned, however, as it could return the same row multiple times.