...

View Full Version : random picture



StickBoy
12-22-2005, 06:55 AM
I am using the following to display a random picture on a particular page:

<SCRIPT TYPE="text/javascript">
var ccPics = new Array()

ccPics[1] = "<img src=\"index01.jpg\" width=435 height=500 alt=\"random picture\" border=0>"

ccPics[2] = "<img src=\"index02.jpg\" width=412 height=500 alt=\"random picture\" border=0>"

var cc = Math.floor(Math.random() * ccPics.length)
if (cc == 0) {
cc = 1
}
document.write(ccPics[cc])
</SCRIPT>

(I have shortened the example to two pictures ... obviously I can use as many pictures as I want.)

I wonder if there is a way to assign a lighter weight to some pictures, to have them display less frequently, or a heavier weight to other pictures to have them display more frequently. Or whatever fix / workaround is necessary.

Thanks!

Philip M
12-22-2005, 07:29 AM
See http://www.javascriptkit.com/javatutors/weighrandom.shtml



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum