Re: consistent random order

From: Jeff Herrin <jeff(at)alternateimage(dot)com>
To: Aaron Bono <postgresql(at)aranya(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: consistent random order
Date: 2006-11-29 17:30:57
Message-ID: 6801364.59051164821457152.JavaMail.root@srv161.carpathiahost.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I need it a little more random than that. In both these scenarios, the same items will always follow each other.

Jeff

----- Original Message -----
Why not create a random seed between 1 and the number of possibilities in your web application when a user first hits the site, store that in the session and then increment it by 1 (do a modulus to wrap the numbers back to 1) and just select with an offset equal to this number?  That way you get the first item chosen at random but the rest are sequential.  If you want this somewhat random, create a "random" ordering field on the table and sort by that so the pages are not sorted by name or id or whatever else it may normally sort by.

You could then take it further and use cookies so the next time that person comes to the site, the "random" page picks up where it left off.

Just an idea...

--
==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
==================================================================

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Herrin 2006-11-29 17:32:56 Re: consistent random order
Previous Message Andreas Kretschmer 2006-11-29 17:27:42 Re: consistent random order