Trying to convert an extended Array.prototype to a function I got a random image rotator working by using the following script (demo). But I was told that it is a bad practice to extend Array.prototype. And it does. It conflicts with the chained select box unless I modify the selected box script. So I guess it's better to not use Array.prototype.shuffle ,isn't it? 

Here's The script:

                Array.prototype.shuffle = function() {
                var s = [];
                while (this.length) s.push(this.splice(Math.random() * this.length, 1));
                while (s.length) this.push(s.pop());
                return this;
            }

            var picData = [
                ['img1','url_1'],
                ['img2','url_2'],
                ['img3','url_3'],

            picO = new Array();
            randIndex = new Array(); 
            for(i=0; i &lt; picData.length; i++){
                picO[i] = new Image();
                picO[i].src = picData[i][0];
                picO[i].alt = picData[i][1];
                randIndex.push(i);
            }
            randIndex.shuffle();
            window.onload=function(){
                var mainImgs = document.getElementById('carouselh').getElementsByTagName('img');


                for(i=0; i &lt; mainImgs.length; i++){
                    mainImgs[i].src = picO[randIndex[i]].src;
                    mainImgs[i].parentNode.href = picData[randIndex[i]][1];
                    mainImgs[i].alt = picData[randIndex[i]][1];
                }

            }


I'm not sure where to start. I'm reading this article, should I do something like

    Array.shuffle = function() {for(var 
a=[];this.length;)a.push(array.splice(Math.random()*array.length,1));
for(;a.length;)this.push(a.pop());return this};


Would anyone please point me in some directions to rewrite that part?
My advice is to use a known shuffle algorithm for this.  

This stackoverflow answer describes the Fisher-Yates shuffle and provides a function for you to use.

https://stackoverflow.com/a/2450976/423413

Bottom line use that function and replace your Array.prototype.shuffle function and call it something like shuffleArray

var shuffleArray = function(arr) {
    ...
}


Then replace the line that says randIndex.shuffle() with a call to the new function.

shuffleArray(randIndex);