PDA

View Full Version : including randomizer



chrigman
09-04-2005, 12:14 PM
hello everyone
i'm using this javascript on my homepage
http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm
and i'm wondering if anyone knows how to include a randomizer (Math.floor(Math.random()" ) something like this i suppose.
really hope you can help me out with this

rgds,
chris

mwinter
09-04-2005, 12:32 PM
Please search for previous posts before asking questions:

Fade-in Slideshow: random display of images how-to (http://www.dynamicdrive.com/forums/showthread.php?t=2564)

It save you, and everyone else, time.

Mike

chrigman
09-04-2005, 04:02 PM
well, thanks for the link
the first two pictures are choosen randomly, but than it sets it on the 4th picture and continues in line down the last one....

chris

jscheuer1
09-04-2005, 04:20 PM
I've used mwinter's excellant randomizing unit on more than several scripts to randomize their arrays, either onload or each time an image is requested by the script. Keep in mind that random means random and can look ordered at times. If something else is at work here, we need to see your code to figure out the problem. Just to be clear, it is post number 6 from the above thread mentioned by Mike that contains the fully formed randomizing unit and it must be used as he describes in that post.

.

chrigman
09-05-2005, 05:46 PM
hello together
well here's the test page with the randomizer
http://chrisgalliker.lucienschranz.com/index.htm
it randomizes the first two but than continues with then continues in row with the Singapore 747, america west 757, and so on....

rgds,
chris

jscheuer1
09-05-2005, 08:27 PM
Replace:

var randomizeimage="yes" //randomize dislay order of images? "yes" or "no"

function shuffleit(){
return Math.floor((Math.random()*fadeimages.length-1))
}

if (randomizeimage=="yes")
fadeimages.sort(shuffleit)with:

var randomizeimage="yes" //randomize display order of images? "yes" or "no"

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;
};

if (randomizeimage=="yes")
fadeimages.shuffle()