Re: Randomizing an Array?


From: jwcooper [mailto:removed_email_address@domain.invalid]

Gavin K. wrote:

From: jwcooper [mailto:removed_email_address@domain.invalid]

I’m trying to randomize an array…[snip]

randomized = my_array.sort_by{ rand }

Thank you so much! It worked perfectly!

No problems. You might search the mailing list archive on this topic if
‘true’ randomness (or close to it) is important to you. IIRC, there was
a discussion a year or so ago about the amount of randomness in this
randomization technique and how it wasn’t quite as random as it could
be. (And other, longer techniques were provided for the times when
really really random sorting was needed.)