|| 

|| > More info, including the Ruby code I used, available at
|| > http://eigenclass.org/hiki.rb?sort_by+rand+is+biased
|| >
|| >> does
|| >>
|| >>   %w( a b c d ).sort{ rand <=> rand }
|| >>
|| >> help?

Hi, I'm new to ruby, but I use Python for some years now.
So I suggest the following 'pythonic' solution ;-)

  def shuffle(a)
      
      b=[]
      # decorate
      a.each { |x| b << [rand,x]; }

      # sort
      b.sort! { |x,y| x[0] <=> y[0] }

      # undecorate
      b.collect { |x| x[1] }
  end

  a=%w{a b c d e f}
  puts shuffle a  

Is there a shorter or more elegant way to do this 
'decorate-sort-undecorate' in ruby ?
In Python it is quite easy by using list comprehensions...


Greetings, Uwe