From: "Brian Schröder" Date: 2005-12-08T00:51:55+09:00 Subject: Re: Shuffling an array, sort_by{rand}'s bias (was Re: need some Ruby magic) On 07/12/05, Michael Ulm wrote: > hmassa@gmail.com wrote: > > > Why not > > a.dup.sort { 2*rand(12345) <=> 12345 } > > > > ? that way, we'd have NO colisions ever. > > > > What you have posted does not avoid collisions. > You probably mean something like > > a.sort {2*rand(12345) <=> 2 * rand(12345) + 1} > > [snip] > and then he should do us a favour and write > a.sort { [-1, 1][rand(2)] } instead, which gives the same skewed results but at least does not do it as complicated. Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/