I have a database with more than a million records. I'm trying to get the records in a randomized order. The database is filled with links to images and each image has an unique number. So I should be able to recreate the same "random" order for the next and previous buttons on the pictures?

Is there a way to come up with a query and save it on a cookie or session and reuse that to regenerate my random order?  

Overall is it efficient because I don't want the load time to go high?

Any suggestion is awesome.