View Full Version : Fade-in slideshow - Random output

10-30-2005, 12:56 AM
I love this script - I've got it creating an array from multiple Cold Fusion Queries.

My request is for code that will randomize the display order of the images in the array. I've ben rackin' my brain on that one for a bit. :confused:


10-30-2005, 03:12 AM
Random means random. This means any slide can follow any slide, this can result in repeats (which will look like the show is not doing anything for a period at least twice as long as the configured pause) and repeated alternations at times, especially if the total number of slides is low. With that in mind, add below the 'NO need to edit beyond here' line:

////NO need to edit beyond here/////////////

//Randomizing Unit Courtesy of Mike Winter as seen at:
function random(n) {
return Math.floor((Math.random() % 1) * n);

Array.prototype.shuffle = function() {var i = this.length;
while(i--) {this.swap(i, random(i + 1));}
Array.prototype.swap = function(x, y) {
var t = this[x]; this[x] = this[y]; this[y] = t;
//End Randomizing Unit


Put this (highlight red) in the insertimage function:

function insertimage(i){
var tempcontainer=fadeimages[i][1]!=""? '<a href="'+fadeimages[i][1]+'" target="'+fadeimages[i][2]+'">' : ""
tempcontainer+='<img src="'+fadeimages[i][0]+'" border="0">'
tempcontainer=fadeimages[i][1]!=""? tempcontainer+'</a>' : tempcontainer
return tempcontainer

I highly recommend that you use this with at least 10 images, any less than that will probably have too many repeats and repeat alternations (going back and forth between just two slides for an extended time).

10-30-2005, 08:22 AM
Worked BEAUtifuly - Thank You!!!