From: Michael Ulm Date: 2005-12-06T22:24:01+09:00 Subject: Re: Shuffling an array, sort_by{rand}'s bias (was Re: need some Ruby magic) Mauricio Fern�ndez wrote: > On Tue, Dec 06, 2005 at 08:23:52AM +0900, ara.t.howard@noaa.gov wrote: > >>the big difference is that a value will have rand called multiple times for > > > That might be the very reason why it is ultimately much more biased than > sort_by{ rand }... I'm keeping the latter. Indeed, ar = [0, 1, 2]; result = Hash.new(0) 100000.times {result[ar.sort {rand <=> rand}] += 1} p result # => {[2, 1, 0]=>25235, [2, 0, 1]=>12285, [1, 0, 2]=>12426, [0, 1, 2]=>25111, [1, 2, 0]=>12468, [0, 2, 1]=>12475} Michael -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-219, fax: +43 2236 21081 e-mail: michael.ulm@isis-papyrus.com Visit our Website: www.isis-papyrus.com