From: Alex Young Date: 2006-06-19T22:27:14+09:00 Subject: Re: Is it more convenient to have a random_each in ruby stdl Leslie Viljoen wrote: > On 6/19/06, uncutstone wu wrote: >> Kroeger, Simon (ext) wrote: >> >> def random_each >> >> >> >> >> >> uncutstone >> > >> > I think it's a little bit to simple to be put in the standard lib. >> > >> > a.sort_by{rand}.each {|e| print e , ' '} >> > >> It is nice to see you make it so simple! > > Surely this would break some sort algorithms, since the same element > can return different sort priorities (using rand)... I assume it > doesn't break Ruby's sort algorithm? > sort_by generates the block value once for each collection element then uses that value for a standard sort, so it's not a problem. -- Alex