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

Reply via email to