View Full Version : random picture

12-22-2005, 07: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

(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.


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