[flashpro] Array order randomizer?
pete otaqui
pete.otaqui at gmail.com
Thu Mar 17 13:27:23 EST 2005
"Method" in this instance refers to an internal function of the Array
object, like this:
Array.prototype.randomize = function() {
var arr = new Array();
var i = 0;
while ( i < this.length ) arr[i] = this[i++];
var rtn = new Array();
while ( arr.length>0 ) {
var n = Math.floor(Math.random()*arr.length);
rtn.push( arr[n] );
arr.splice( n, 1 );
}
return rtn;
}
var a = new Array("a","b","c","d","e","f");
var b = a.randomize();
trace( b );
(note - I'm not sure this is the best way to do this, but it avoids
distorting the original array).
pete
On Thu, 17 Mar 2005 11:39:10 +0100, Timo Stamm <t.stamm at macnews.de> wrote:
> Thanks.
>
>
> Timo
> ------------------------------------------------------------------
> send message to the list: mailto:flashpro at muinar.org
> [FlashPro] list info, subscribe, archive: http://flash-list.com/
> There's also a WebPro mailing list: http://webdesign-list.com/
> cutting-edge sounds for flash: http://flash-sounds.com/
>
--
pete otaqui
new media developer
pete.otaqui at gmail.com
pete at thisnewthing.com
More information about the FlashPro
mailing list