View Full Version : 3 random image/links on same page... no repeats

04-25-2006, 08:04 PM
I need to create a series of three random thumbnail images on a page w/ every reload.

But none of the 3 can be repeats of the other two images.

Anyone know a code for this? I know how to do random images, but I don't know how to ensure that there are no repeats.

Thank you

04-25-2006, 08:10 PM
Using PHP with mySQL is generally a better solution than using JavaScript for this type of thing.

If you absolutely have to use JavaScript, you can run the random image/text chosen through a for loop to make sure it doesn't match the others. There are a lot of scripts out there premade for you, just do a quick Google search and you'll find something.

04-25-2006, 11:37 PM
Javascript solution (no loops required):

var imgArray = ['img1.gif','img2.gif','img3.gif', ......'img100.gif'];
function randOrd(){return (Math.round(Math.random())-0.5); }
var pic1 = imgArray[0]; // first random image
var pic2 = imgArray[1]; // second random image
var pic3 = imgArray[2]; // third random image

Still better done on the server though if you can.

04-26-2006, 03:58 AM
Thanks alot, that'll work great...