RE: [PHP] Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites
| From: | Jon Haworth | Date: | Fri, 20 Aug 2010 11:11:50 +0000 |
| Subject: | RE: [PHP] Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307597@lists.php.net to get a copy of this message | ||
Hi Col,
Interesting problem.
> Are there any other approaches I've missed?
Off the top of my head, how about this:
1. Add a new unsigned int column called "SortOrder" to the table of widgets
or whatever it is you're listing
2. Fill this column with randomly-generated numbers between 0 and whatever
the unsigned int max is (can't remember exactly but 4.2 billion ish)
3. Add the SortOrder column to the end of all your ORDER BY clauses - SELECT
foo ORDER BY TypeOfListing, SortOrder will give you widgets sorted by
Gold/Silver/Bronze type, but in a random order for each type
4. Every hour/day/week/whatever, update this column with different random
numbers
Advantages: practically no hassle/overhead/maintenance for you; provides
same ordering sequence for all users at the same time; only breaks "third
one down"-type references when you refresh the SortOrder column rather than
on each session or page view; reasonably proxy- and cache-friendly
especially if you send a meaningful HTTP Expires header.
Disadvantages: breaks user persistence if they visit before and after a
SortOrder refresh ("I'm sure the one I wanted was at the top of the list
yesterday..."); more effort to demonstrate randomness to the client ("OK,
see how you're in ninety-third place today? Well, check again tomorrow and
you should be somewhere else on the list").
Hopefully food for thought anyway.
Cheers
Jon