From: Bill Kelly Date: 2005-12-07T01:12:14+09:00 Subject: Re: Shuffling an array, sort_by{rand}'s bias (was Re: need some Ruby Hi, From: "Uwe Schmitt" > || > || On Tue, Dec 06, 2005 at 07:32:34PM +0900, Uwe Schmitt wrote: > || > Is there a shorter or more elegant way to do this > || > 'decorate-sort-undecorate' in ruby ? > || > || arr.sort_by{rand} > > that is not equivalent to my solution. > the python equivalent to yours is > > arr.sort(key = lambda x: random()) No, Array#sort_by does the 'decorate-sort-undecorate', aka. Schwartzian Transform. I don't read Python very well, but I think the ruby equivalent to 'arr.sort(key = lambda x: random())' might be: arr.sort { rand <=> rand } But that is different from arr.sort_by {rand} Regards, Bill