If you can filter the results after accessing the database, or you can send a request using order by and process the results with the reader, then you can add a probabilistic bias to the selection. You see that the higher the offset, the more difficult the test inside the if , the more random the process.
var table = ... // This is ordered with latest records first int nItems = 10; // Number of items you want double bias = 0.5; // The probabilistic bias: 0=deterministic (top nItems), 1=totally random Random rand = new Random(); var results = new List<DataRow>(); // For example... for(int i=0; i<table.Rows.Count && results.Count < nItems; i++) { if(rand.NextDouble() > bias) // Pick the current item probabilistically results.Add(table.Rows[i]); // Or reader.Next()[...] }
source share