RE: [Flashcoders] array copy with random order
@Mark - Thanks for the suggestion @Steven - Thanks for the code! This does work better than the others. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks Sent: Monday, August 13, 2007 3:16 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] array copy with random order Fisher-Yates shuffle algorithm in AS2: function fisherYates(myArray:Array):Void { var i:Number = myArray.length; if (i > 0) { while (--i) { var j:Number = Math.floor(Math.random() * (i + 1)); var tempi:Object = myArray[i]; var tempj:Object = myArray[j]; myArray[i] = tempj; myArray[j] = tempi; } } } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mark Hawley Sent: Monday, August 13, 2007 2:45 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] array copy with random order Just look up "Fisher-Yates shuffle" and use it. It's better than any number of home-rolled randomizers. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
Fisher-Yates shuffle algorithm in AS2: function fisherYates(myArray:Array):Void { var i:Number = myArray.length; if (i > 0) { while (--i) { var j:Number = Math.floor(Math.random() * (i + 1)); var tempi:Object = myArray[i]; var tempj:Object = myArray[j]; myArray[i] = tempj; myArray[j] = tempi; } } } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
Just look up "Fisher-Yates shuffle" and use it. It's better than any number of home-rolled randomizers. On 8/13/07, Jesse Graupmann <[EMAIL PROTECTED]> wrote: > > Steven, > > I'm not really sure how to compare the differences between array sorts, > but > this seemed pretty straight forward. > > >From what I can tell, using Math.round(Math.random()*2)-1 produced less > movement in original number position than Math.round(Math.random()). > > > > // > // TEST > // > > var array = [0,1, 2, 3, 4, 5, 6, 7, 8, 9 ]; > > function randomizeArray ( a ) { > // 0, 1 > var na = [].concat(a).sort ( function (){ return > Math.round(Math.random()); } ); > analyzeArray( na ); > return na; > } > function randomizeArray2 ( a ) { > // -1, 0, 1 > var na = [].concat(a).sort ( function (){ return > Math.round(Math.random()*2)-1; } ); > analyzeArray( na ); > return na; > } > > function analyzeArray ( a ) > { > var len = a.length; > var mov = new Array (len); > var med = 0; > var avg = 0; // average movement > var ttl = 0; // total movement > > for ( var i = 0; i < len; i++ ) > { > var num = a[i]; > var dist = i-num; > mov [num] = dist; > med += dist; > ttl += Math.abs( dist ); > } > > avg = ttl / len; > trace('\nttl: ' + ttl + ' avg: ' + avg + ' med: ' + med + ' > mov: ' + mov ) > } > > trace( '\n++ 1\n'); > > trace (randomizeArray ( array )); > trace (randomizeArray ( array )); > trace (randomizeArray ( array )); > trace (randomizeArray ( array )); > trace (randomizeArray ( array )); > trace (randomizeArray ( array )); > trace (randomizeArray ( array )); > > trace( '\n++ 2\n'); > > trace (randomizeArray2 ( array )); > trace (randomizeArray2 ( array )); > trace (randomizeArray2 ( array )); > trace (randomizeArray2 ( array )); > trace (randomizeArray2 ( array )); > trace (randomizeArray2 ( array )); > trace (randomizeArray2 ( array )); > > trace( '\n++ org\n'); > > trace( array ); // no change good > > > // > // OUTPUT > // > > ++ 1 > > > ttl: 30 avg: 3 med: 0 mov: 7,0,6,2,-1,-1,0,-7,-6,0 > 7,1,8,4,5,3,6,0,2,9 > > ttl: 38 avg: 3.8 med: 0 mov: 9,-1,2,5,2,-2,1,-5,-3,-8 > 1,9,7,5,2,8,4,6,3,0 > > ttl: 22 avg: 2.2 med: 0 mov: 4,1,-1,-3,4,2,0,-2,-5,0 > 3,2,1,8,0,7,6,5,4,9 > > ttl: 12 avg: 1.2 med: 0 mov: 4,0,-2,0,-2,0,0,1,1,-2 > 2,1,4,3,0,5,6,9,7,8 > > ttl: 30 avg: 3 med: 0 mov: 7,0,4,-1,-4,4,-1,-3,-5,-1 > 4,1,3,8,7,6,2,0,9,5 > > ttl: 22 avg: 2.2 med: 0 mov: 7,0,-2,2,0,1,-3,1,-6,0 > 2,1,8,6,4,3,5,0,7,9 > > ttl: 36 avg: 3.6 med: 0 mov: 7,2,6,3,-2,0,-5,-7,-4,0 > 7,6,4,1,8,5,3,0,2,9 > > ++ 2 > > > ttl: 16 avg: 1.6 med: 0 mov: 0,5,3,-1,-3,-2,-2,0,0,0 > 0,4,3,5,6,2,1,7,8,9 > > ttl: 24 avg: 2.4 med: 0 mov: 0,0,7,1,2,-2,2,-2,-1,-7 > 0,1,9,5,3,7,4,8,6,2 > > ttl: 32 avg: 3.2 med: 0 mov: 1,8,3,0,2,-3,2,0,-4,-9 > 9,0,5,3,8,2,4,7,6,1 > > ttl: 10 avg: 1 med: 0 mov: 0,0,1,4,0,-3,0,-2,0,0 > 0,1,5,2,4,7,6,3,8,9 > > ttl: 22 avg: 2.2 med: 0 mov: 0,0,4,5,1,-1,-4,0,1,-6 > 0,1,6,9,5,4,2,7,3,8 > > ttl: 20 avg: 2 med: 0 mov: 0,2,2,-1,3,3,-5,-1,-3,0 > 0,6,3,1,2,8,7,4,5,9 > > ttl: 22 avg: 2.2 med: 0 mov: 1,6,0,0,0,4,-1,-1,0,-9 > 9,0,2,3,4,6,7,1,8,5 > > ++ org > > 0,1,2,3,4,5,6,7,8,9 > > > > > _ > > Jesse Graupmann > www.jessegraupmann.com > www.justgooddesign.com/blog/ > _ > > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Steven > Sacks > Sent: Monday, August 13, 2007 11:23 AM > To: flashcoders@chattyfig.figleaf.com > Subject: Re: [Flashcoders] array copy with random order > > > array2.sort ( function (){ return Math.round(Math.random()); } ); > > That's brilliant! :) > > To build upon that with all 3 outcomes (-1, 0, 1), you can use: > > Math.round(Math.random() * 2) - 1) > > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] array copy with random order
Steven, I'm not really sure how to compare the differences between array sorts, but this seemed pretty straight forward. >From what I can tell, using Math.round(Math.random()*2)-1 produced less movement in original number position than Math.round(Math.random()). // // TEST // var array = [0,1, 2, 3, 4, 5, 6, 7, 8, 9 ]; function randomizeArray ( a ) { // 0, 1 var na = [].concat(a).sort ( function (){ return Math.round(Math.random()); } ); analyzeArray( na ); return na; } function randomizeArray2 ( a ) { // -1, 0, 1 var na = [].concat(a).sort ( function (){ return Math.round(Math.random()*2)-1; } ); analyzeArray( na ); return na; } function analyzeArray ( a ) { var len = a.length; var mov = new Array (len); var med = 0; var avg = 0; // average movement var ttl = 0; // total movement for ( var i = 0; i < len; i++ ) { var num = a[i]; var dist = i-num; mov [num] = dist; med += dist; ttl += Math.abs( dist ); } avg = ttl / len; trace('\nttl: ' + ttl + ' avg: ' + avg + ' med: ' + med + ' mov: ' + mov ) } trace( '\n++ 1\n'); trace (randomizeArray ( array )); trace (randomizeArray ( array )); trace (randomizeArray ( array )); trace (randomizeArray ( array )); trace (randomizeArray ( array )); trace (randomizeArray ( array )); trace (randomizeArray ( array )); trace( '\n++ 2\n'); trace (randomizeArray2 ( array )); trace (randomizeArray2 ( array )); trace (randomizeArray2 ( array )); trace (randomizeArray2 ( array )); trace (randomizeArray2 ( array )); trace (randomizeArray2 ( array )); trace (randomizeArray2 ( array )); trace( '\n++ org\n'); trace( array ); // no change good // // OUTPUT // ++ 1 ttl: 30 avg: 3 med: 0 mov: 7,0,6,2,-1,-1,0,-7,-6,0 7,1,8,4,5,3,6,0,2,9 ttl: 38 avg: 3.8 med: 0 mov: 9,-1,2,5,2,-2,1,-5,-3,-8 1,9,7,5,2,8,4,6,3,0 ttl: 22 avg: 2.2 med: 0 mov: 4,1,-1,-3,4,2,0,-2,-5,0 3,2,1,8,0,7,6,5,4,9 ttl: 12 avg: 1.2 med: 0 mov: 4,0,-2,0,-2,0,0,1,1,-2 2,1,4,3,0,5,6,9,7,8 ttl: 30 avg: 3 med: 0 mov: 7,0,4,-1,-4,4,-1,-3,-5,-1 4,1,3,8,7,6,2,0,9,5 ttl: 22 avg: 2.2 med: 0 mov: 7,0,-2,2,0,1,-3,1,-6,0 2,1,8,6,4,3,5,0,7,9 ttl: 36 avg: 3.6 med: 0 mov: 7,2,6,3,-2,0,-5,-7,-4,0 7,6,4,1,8,5,3,0,2,9 ++ 2 ttl: 16 avg: 1.6 med: 0 mov: 0,5,3,-1,-3,-2,-2,0,0,0 0,4,3,5,6,2,1,7,8,9 ttl: 24 avg: 2.4 med: 0 mov: 0,0,7,1,2,-2,2,-2,-1,-7 0,1,9,5,3,7,4,8,6,2 ttl: 32 avg: 3.2 med: 0 mov: 1,8,3,0,2,-3,2,0,-4,-9 9,0,5,3,8,2,4,7,6,1 ttl: 10 avg: 1 med: 0 mov: 0,0,1,4,0,-3,0,-2,0,0 0,1,5,2,4,7,6,3,8,9 ttl: 22 avg: 2.2 med: 0 mov: 0,0,4,5,1,-1,-4,0,1,-6 0,1,6,9,5,4,2,7,3,8 ttl: 20 avg: 2 med: 0 mov: 0,2,2,-1,3,3,-5,-1,-3,0 0,6,3,1,2,8,7,4,5,9 ttl: 22 avg: 2.2 med: 0 mov: 1,6,0,0,0,4,-1,-1,0,-9 9,0,2,3,4,6,7,1,8,5 ++ org 0,1,2,3,4,5,6,7,8,9 _ Jesse Graupmann www.jessegraupmann.com www.justgooddesign.com/blog/ _ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks Sent: Monday, August 13, 2007 11:23 AM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] array copy with random order > array2.sort ( function (){ return Math.round(Math.random()); } ); That's brilliant! :) To build upon that with all 3 outcomes (-1, 0, 1), you can use: Math.round(Math.random() * 2) - 1) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
This technique is dangerous for algorithms that work with how sorted the array already is, like bubble sort. The condition that bubble sort depends on to know when the array is sorted is whether it had to swap any numbers. The speed of sort algorithms also depends on how many times a swap occurs. I doubt that the adobe sort function uses bubble sort or anything of the like, it's likely of O(N log N) complexity, which is of the fastest known, but still slower than an array shuffle function which should be O(N). On 8/13/07, T. Michael Keesey <[EMAIL PROTECTED]> wrote: > > On 8/13/07, Steven Sacks <[EMAIL PROTECTED]> wrote: > > > array2.sort ( function (){ return Math.round(Math.random()); } ); > > > > That's brilliant! :) > > > > To build upon that with all 3 outcomes (-1, 0, 1), you can use: > > > > Math.round(Math.random() * 2) - 1) > > Very interesting. But any time you use random numbers, you should be > careful. I think this strategy may have the potential of taking a > really long time once in a while, since the Array.sort function > expects the "compare" function to return consistent results (i.e., if > A < B then B > A, and if A == B then B == A). Of course, I'm not sure > about this (anyone know which algorithm Array.sort uses?) and even if > it's true, "once in a while" probably means something like "once in a > million times". If it's for a fun game or something, it's probably > fine, but if it's for something with greater consequences for errors, > you might want to take a closer look. (I missed the beginning of this > thread, unfortunately.) > > -- > Mike Keesey > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
On 8/13/07, Steven Sacks <[EMAIL PROTECTED]> wrote: > > array2.sort ( function (){ return Math.round(Math.random()); } ); > > That's brilliant! :) > > To build upon that with all 3 outcomes (-1, 0, 1), you can use: > > Math.round(Math.random() * 2) - 1) Very interesting. But any time you use random numbers, you should be careful. I think this strategy may have the potential of taking a really long time once in a while, since the Array.sort function expects the "compare" function to return consistent results (i.e., if A < B then B > A, and if A == B then B == A). Of course, I'm not sure about this (anyone know which algorithm Array.sort uses?) and even if it's true, "once in a while" probably means something like "once in a million times". If it's for a fun game or something, it's probably fine, but if it's for something with greater consequences for errors, you might want to take a closer look. (I missed the beginning of this thread, unfortunately.) -- Mike Keesey ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
> array2.sort ( function (){ return Math.round(Math.random()); } ); That's brilliant! :) To build upon that with all 3 outcomes (-1, 0, 1), you can use: Math.round(Math.random() * 2) - 1) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
Well you could But, while for..each does not guarantee any particular order, it does not guarantee to be random either :-) i.e. It might turn out that, in the next version of the flash player, they find that they can have a more optimised implementation by running the loop in array order. Personally, I'd actually write the randomisation code, rather than rely on internals. For a start, it won't exactly be obvious what the code is even doing. Peter On 8/13/07, Johannes Nel <[EMAIL PROTECTED]> wrote: > in as3 you could just dish it up using a for each loop > > On 8/13/07, Cedric Muller <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > There's that good old shuffleArray, don't know if that will be > > sufficient: > > > > function shuffleArray (arr_p:Array):Array { > > var len:Number = arr_p.length, mixed:Array = arr_p.slice(), > > rn:Number, it:Number, el:Object; > > for (it = 0; it > el = mixed[it]; > > mixed[it] = mixed[rn = random(len)]; > > mixed[rn] = el; > > } > > return mixed; > > } > > > > var myArr = new Array(40, 32, 90, 76, 66); > > var rdnArr = shuffleArray(myArr); > > // or > > myArr = shuffleArray(myArr); > > > > hth, > > cedric > > > > > > > Hi > > > > > > I have one Array with random numbers [40,32,90,76,66] > > > > > > I need copy of this array but the order should be different and > > > random. > > > Something like this: [76,90,40,32,66]. How can this be done? > > > Thanks for any help. > > > ___ > > > Flashcoders@chattyfig.figleaf.com > > > To change your subscription options or search the archive: > > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > Brought to you by Fig Leaf Software > > > Premier Authorized Adobe Consulting and Training > > > http://www.figleaf.com > > > http://training.figleaf.com > > > > ___ > > Flashcoders@chattyfig.figleaf.com > > To change your subscription options or search the archive: > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > Brought to you by Fig Leaf Software > > Premier Authorized Adobe Consulting and Training > > http://www.figleaf.com > > http://training.figleaf.com > > > > > > -- > j:pn > http://www.memorphic.com/news/ > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
My archive doesn't go back to the original thread, but I found a reference to it: Array.prototype.shuffle = function() { var i = this.length; while (i) { var p = random(i); var t = this[--i]; this[i] = this[p]; this[p] = t; } } That's the solution Fumio Nonaka and Tatsuo Kato came up with back in the day. It was a classic, extensive discussion on the topic here, from a very long time ago. I still remember following it, as a young coder, watching how some of the greatest FlashCoders of the time discussed what the fastest way of shuffling an array might be. Ah, well. Those were the days... Mark ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
THANK you very much!!! 2007/8/13, Johannes Nel <[EMAIL PROTECTED]>: > > in as3 you could just dish it up using a for each loop > > On 8/13/07, Cedric Muller <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > There's that good old shuffleArray, don't know if that will be > > sufficient: > > > > function shuffleArray (arr_p:Array):Array { > > var len:Number = arr_p.length, mixed:Array = arr_p.slice(), > > rn:Number, it:Number, el:Object; > > for (it = 0; it > el = mixed[it]; > > mixed[it] = mixed[rn = random(len)]; > > mixed[rn] = el; > > } > > return mixed; > > } > > > > var myArr = new Array(40, 32, 90, 76, 66); > > var rdnArr = shuffleArray(myArr); > > // or > > myArr = shuffleArray(myArr); > > > > hth, > > cedric > > > > > > > Hi > > > > > > I have one Array with random numbers [40,32,90,76,66] > > > > > > I need copy of this array but the order should be different and > > > random. > > > Something like this: [76,90,40,32,66]. How can this be done? > > > Thanks for any help. > > > ___ > > > Flashcoders@chattyfig.figleaf.com > > > To change your subscription options or search the archive: > > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > Brought to you by Fig Leaf Software > > > Premier Authorized Adobe Consulting and Training > > > http://www.figleaf.com > > > http://training.figleaf.com > > > > ___ > > Flashcoders@chattyfig.figleaf.com > > To change your subscription options or search the archive: > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > Brought to you by Fig Leaf Software > > Premier Authorized Adobe Consulting and Training > > http://www.figleaf.com > > http://training.figleaf.com > > > > > > -- > j:pn > http://www.memorphic.com/news/ > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
in as3 you could just dish it up using a for each loop On 8/13/07, Cedric Muller <[EMAIL PROTECTED]> wrote: > > Hi, > > There's that good old shuffleArray, don't know if that will be > sufficient: > > function shuffleArray (arr_p:Array):Array { > var len:Number = arr_p.length, mixed:Array = arr_p.slice(), > rn:Number, it:Number, el:Object; > for (it = 0; it el = mixed[it]; > mixed[it] = mixed[rn = random(len)]; > mixed[rn] = el; > } > return mixed; > } > > var myArr = new Array(40, 32, 90, 76, 66); > var rdnArr = shuffleArray(myArr); > // or > myArr = shuffleArray(myArr); > > hth, > cedric > > > > Hi > > > > I have one Array with random numbers [40,32,90,76,66] > > > > I need copy of this array but the order should be different and > > random. > > Something like this: [76,90,40,32,66]. How can this be done? > > Thanks for any help. > > ___ > > Flashcoders@chattyfig.figleaf.com > > To change your subscription options or search the archive: > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > Brought to you by Fig Leaf Software > > Premier Authorized Adobe Consulting and Training > > http://www.figleaf.com > > http://training.figleaf.com > > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > -- j:pn http://www.memorphic.com/news/ ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] array copy with random order
Hi, There's that good old shuffleArray, don't know if that will be sufficient: function shuffleArray (arr_p:Array):Array { var len:Number = arr_p.length, mixed:Array = arr_p.slice(), rn:Number, it:Number, el:Object; for (it = 0; it Hi I have one Array with random numbers [40,32,90,76,66] I need copy of this array but the order should be different and random. Something like this: [76,90,40,32,66]. How can this be done? Thanks for any help. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] array copy with random order
var array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; var array2 = [].concat(array); array2.sort ( function (){ return Math.round(Math.random()); } ); trace( array ); // 0,1,2,3,4,5,6,7,8,9 trace( array2 ); // 8,2,3,6,5,4,1,7,0,9 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of natalia Vikhtinskaya Sent: Monday, August 13, 2007 2:29 AM To: Flashcoders mailing list Subject: [Flashcoders] array copy with random order Hi I have one Array with random numbers [40,32,90,76,66] I need copy of this array but the order should be different and random. Something like this: [76,90,40,32,66]. How can this be done? Thanks for any help. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com