From: Uwe Schmitt Date: 2005-12-06T23:32:34+09:00 Subject: Re: Shuffling an array, sort_by{rand}'s bias (was Re: need some Ruby || || On Tue, Dec 06, 2005 at 07:32:34PM +0900, Uwe Schmitt wrote: || > Hi, I'm new to ruby, but I use Python for some years now. || > So I suggest the following 'pythonic' solution ;-) || [...] || > 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()) || || > In Python it is quite easy by using list comprehensions... || What does that look like in Python? from random import random def shuffle(a): b = [ (random(), i) for i in a] b.sort() return [ x[1] for x in b ] print shuffle(range(10)) || Is it shorter than the above one? }:-) || || -- || Mauricio Fernandez greetings, Uwe ||