[thelist] random image w/ accompanying text?

Warden, Matt mwarden at odyssey-design.com
Sun Jul 2 23:23:24 CDT 2000

> I don't care too much if it's client-side or server-side.  I'm
> inclined to lean toward server-side just because it "looks" cleaner.
> I'm less experienced with Perl/CGI but willing to try stringing up a
> pre-made script.
> But client or server side would either/both be okay, as long as
> something comes up when JS is turned off.

Seems to me that your best bet is to use a two-dimentional array...

String[] myArray;
myArray[0][0] = "1.gif";
myArray[0][1] = "caption one";
myArray[n][0] = "n.gif";
myArray[n][1] = "caption n";

and then use a formula to get a random index. Assuming that the function
random() generates a "random" number between 0 and 1...

int myRandomIndex = random() * n;

depending on whether or not random() can generate 0 and 1, or just numbers
*between* 0 and 1, you might have to make adjustments. Or else,
myArray[0][0|1] will never be accessed.

so, you just do a: myArray[myRandomIndex][0] for the image source and a:
myArray[myRandomIndex][1] for the caption.


More information about the thelist mailing list