From: Mikael Brockman Date: 2004-07-12T08:19:01+09:00 Subject: Re: Ruby quickies and useful idioms gabriele renzi writes: > il Mon, 12 Jul 2004 07:55:58 +0900, Mikael Brockman > ha scritto:: > >> >>Here's some shuffling stuff: >> >>| class Array >>| def shuffle! >>| each_index do |j| >>| i = rand(size - j) >>| self[j], self[j+i] = self[j+i], self[j] >>| end >>| self >>| end >>| >>| def shuffle >>| self.clone.shuffle! >>| end >>| end >> >>And that's it. > > the best shuffle I can think of is the Grossian shuffle (quoting > Flroain Gross (actually written with a different character than ss): > > class Array > def shuffle > sort_by {rand} > end > end > > You may even found extensions.rubyforge.org interesting It's very nifty indeed. I heard it was biased in some obscure way, though. mikael