Re: [Flashcoders] Howto randomize the elements of an array?

2006-04-18 Thread Danny Kodicek
I have an array with up to 1 elements. These elements are sorted of some kind and I need to reorganize the elements so that their positions becomes absolutely random. I guess my best approach would be to assign my own sort function to the Array.sort() method which did nothing but return

Re: [Flashcoders] Howto randomize the elements of an array?

2006-04-18 Thread Mikko Törmälä
I'd do it like this: Take a new array, take a random element from the oldArray and remove it from the oldArray. Then put it as the next element in the newArray. like so: var oldArray:Array = [item1,item2,item3,item4,item5,item6]; var newArray:Array = []; while (oldArray.length) {

Re: [Flashcoders] Howto randomize the elements of an array?

2006-04-18 Thread GregoryN
Martin, Have you looked at http://proto.layer51.com/l.aspx?p=3 There are about 10 custom methods of shuffle-like. I haven't tested them for performance though :-). -- Best regards, GregoryN http://GOusable.com Flash components

Re: [Flashcoders] Howto randomize the elements of an array?

2006-04-18 Thread Fumio Nonaka
See: [Flashcoders] Array.shuffle http://chattyfig.figleaf.com/pipermail/flashcoders/2002-August/043766.html _ Danny Kodicek wrote: The basic randomisation algorithm is: take a new array for each element in the old array: add it at a random position in the new array It's not really rocket