From: Rick DeNatale Date: 2008-07-04T02:46:34+09:00 Subject: Re: pseudo-randomize an array in a consistent order ------=_Part_861_21340149.1215107382564 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thu, Jul 3, 2008 at 1:44 PM, Rick DeNatale wrote: > > > # Swap self[i] and self[j] > # This might be more elegant using a parallel assignment, but > # parallel assignment generates a temporary array, so this is > # a little closer to the C code > tmp = self[i] > self[i] = self[j] > self[j] = self[i] > There's a typo here the line above should be self[j] = tmp > > i -= 1 > end > self > end > > def shuffle > self.dup.shuffle! > end > end > > So shuffle is O(n) whereas any sort is going to be O(>n) > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ------=_Part_861_21340149.1215107382564--