From: Hal Fulton Date: 2004-07-18T22:57:31+09:00 Subject: Re: [NUBY] Ruby Way code for shuffling an array doesn't behave as expected Florian Gross wrote: > Alexey Verkhovsky wrote: > >> One example in The Ruby Way claims that in the following snippet second >> line shuffles the a (i.e., makes an array consisting of the same >> elements as a, but in a different order). > > > By the way, if you just want to shuffle an Array you can also use the > much simpler ary.sort_by { rand }. (It will get minimally biased with > containers containing millions of elements, but that can be fixed by > using Array.new(32) { rand } instead of rand.) And by the way, the code which modified the array while iterating was probably ill-advised from the beginning, although it did work in 1.6.8. Hal