From: Max Williams Date: 2008-07-04T01:59:14+09:00 Subject: Re: pseudo-randomize an array in a consistent order ThoML wrote: > On Jul 3, 4:56 pm, Max Williams wrote: >> Does anyone know how to pseudo-randomize an array (eg with a seed) so >> that you get the same order every time you do it? > > ruby19 has a Array#shuffle method: > irb(main):001:0> Kernel.srand(1); [1,2,3,4,5].shuffle > => [2, 4, 1, 5, 3] > irb(main):002:0> Kernel.srand(1); [1,2,3,4,5].shuffle > => [2, 4, 1, 5, 3] I'm only on 1.8.6 (and not likely to change soon since we'd want to do all our work servers as well), but out of interest, do you know how shuffle compares to .sort_by{rand} (thanks rob!) in terms of efficiency? -- Posted via http://www.ruby-forum.com/.