in reply to Re: Randomize an array
in thread Randomize an array

The one-line should be a good shuffle. However it is O(n log(n)) and Fisher-Yate's is O(n), so the longer code really is better algorithmically.
  • Comment on RE (tilly) 2 (one is worse): Re: Randomize an array

Replies are listed 'Best First'.
RE: RE (tilly) 2 (one is worse): Re: Randomize an array
by Adam (Vicar) on Sep 08, 2000 at 03:34 UTC
    I really should have paid more attention in Algorithm's analysis. Sigh. Maybe I'll take the next level of it when I go back to grad school. You are right. Sort is an implementation of QuickSort ( O(n log n) using lots of memory) while Fisher-Yates is O(n) with a constant defined only by how long it takes to do the rand and the swap. (We had that discussion already. <grin>) So this makes sense. And of course, this defends my suggestion that Fisher-Yates is preferable to the one-liner. Thanks tilly, maybe one day my education will start to sink in.