From: Maarten Boonen Date: 2004-12-16T07:12:15+09:00 Subject: Re: [ANN] rand.rb 0.9: Random access methods for Enumerables Neil Spring schreef: > On Dec 14, 2004, at 7:24 PM, Ilmari Heikkinen wrote: > >> rand.rb is a library for picking random elements and shuffling. >> This work is licensed under the same terms as Ruby itself. > > > umm, could you maybe replace: > > def shuffle! > sort!{rand <=> 0.5} > end > > with: > > def shuffle! > each_index {|j| i = rand(size-j); self[j], self[j+i] = self[j+i], > self[j]} > self > end I made this a function a few days ago and it seems to be a lot faster. Not sure if it's completely correct though. def shuffle! a = 0 while(a