a weighted order by rand()?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am managing banners visualization using a php/mysql script.

Currently, the banner is extracted from a table using a "select * from
banners order by rand limit 1" query.

Anyway this is a completely random extraction. I would like to
introduce a weight in order to have some banner extracted more
frequently. Is there any way to do this (note that I can not modify the
table adding more times the same banners).


Re: a weighted order by rand()?

*** numismatica@gmail.com wrote/escribió (15 May 2005 05:55:33 -0700):
Quoted text here. Click to load it
Quoted text here. Click to load it

I haven't done the math to calculate probabilities but...

select rand()*weight as random_position
from banners
order by random_position desc

-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group

Site Timeline