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
_______________________________________________
[email protected]
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