views:

56

answers:

1

Okay, I found lots of posts on SO about how to pull a RANDOM item from the database when using LINQ. There seems to be a couple of differnet ways to handle this. What I need to do though is pull a RANDOM item from the database that the user has not seen before.

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

Should I put a cookie on the users system recording the IDs of which items they have seen, pull a random record, check to see if it is seen and if so, pull from the database again? That seems like performance issues just waiting to happen.

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 go about this.

Need more details? Just let me know!

+1  A: 

The usual answer to this question is to create a randomly ordered list and scroll through it linearly. So you'd 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 walk.

Mike Burton
I'd also add - you can store a seed and ordinal position associated with the individual, so that you don't have to store the entire sequence - it allows you to recompute and start where they left off.
Jeff Meatball Yang
That'll definititely work when you have a well-defined key sequence of some kind. I'd be concerned about how to connect that ordering to a set of records that has holes in the key sequence.
Mike Burton
I did end up using a shuffle algorithm, at this point I am still going back to the DB to check if the item has been seen yet. The problem I've run into is this can be over multiple visits to the site and the data does change.
Jeremy H