From: transfire@... Date: 2006-06-19T19:19:47+09:00 Subject: Re: Is it more convenient to have a random_each in ruby stdlib? Alex Young wrote: > Kroeger, Simon (ext) wrote: > > > > > >> From: uncutstone wu > >> Sent: Monday, June 19, 2006 9:54 AM > > >> class Array > >> def random_each > >> a = self.dup > > > > I think it's a little bit to simple to be put in the standard lib. > > > > a.sort_by{rand}.each {|e| print e , ' '} > > For large collections, it'd be much nicer not to have to either > duplicate or sort - isn't this something that quasirandom sequences are > good for? Is there some GSL-guru out there who can comment? Perhaps... class Array def random_each ((0...size).to_a.sort_by{rand}).each { |i| yield self[i] } end end T.