How to pull RANDOM and UNIQUE record from SQL via LINQ

Ok, I found many posts on how to pull a RANDOM item from a database when using LINQ. There seem to be multiple differnet ways to handle this. What I need to do is pull the RANDOM item from the database that the user hasn't seen before.

The data I am pulling from the database is very small. Is there a way I can just hit the database once for 1000 records and then randomly scroll through them?

Should I put a cookie on the users' system, record the IDs of the items they saw, pull a random record, check if it is visible, and if so, pull it out of the database again? This is similar to the performance issues that are expected.

I don't expect anyone to code it for me, I am just looking for concepts and pointing in the right direction of how I should do it.

Need more information? Just let me know!

+2


a source to share


1 answer


The usual answer to this question is to create a randomly ordered list and loop through it linearly. So you pull

a, b, c, d, e, f

      

re-sort it using a randomization algorithm to



b, e, f, a, c, d

      

and then just do a linear move.

+1


a source







All Articles