Page 1 of 1

Random image weighting

Posted: Wed Apr 14, 2004 10:10 am
by JayBird
I am about to create a script that will display random images.

The image paths and descriptions will be stored in a MySQL database.

Now, i want to be able to weight the images, so that images that are higher weighted are more likely to be shown than images that are weighted lower.

I have no idea where to even start with this idea!?

Any suggestions?

Mark

Posted: Wed Apr 14, 2004 10:12 am
by malcolmboston
in the last week i have created half a dozen "random" scripts

what do you mean by "higher weighted" ?

viewed more?

Posted: Wed Apr 14, 2004 10:16 am
by JayBird
malcolmboston wrote:what do you mean by "higher weighted" ?

viewed more?
No, say i have a system where i give each image a number between 1-5.

Images that are weighted 5 have more chance of being display than images which are rated 1.

Mark

Posted: Wed Apr 14, 2004 10:16 am
by magicrobotmonkey
create an array with image names to choose randomly from and put the ones you want "higher weighted" in the array more times, like buying more raffle tickets

Posted: Wed Apr 14, 2004 10:19 am
by JayBird
magicrobotmonkey wrote:create an array with image names to choose randomly from and put the ones you want "higher weighted" in the array more times, like buying more raffle tickets
aha, you may be oto something there. Like if i weight it 5, it appears in the array 5 times.

Hmmmm....

Mark

Posted: Wed Apr 14, 2004 10:29 am
by JayBird
Actually could do it like this

Code: Select all

priority=array( 
    "HI", 
    "HI", 
    "HI", 
    "MED", 
    "MED", 
    "LO" 
); 

$pri=rand(0,sizeof($priority)-1); 
$query="Select * FROM $ads_image WHERE status=1 AND priority=" . $priority[$pri];
Mark

Posted: Wed Apr 14, 2004 10:34 am
by magicrobotmonkey
Yea that was more what I meant then the first one. it would be pretty easy to write a function to take an image name, an array, and a weight and insert the image name into the array weight times and the array would just be holding image names so it wouldnt be a size problem.