Forum: Ruby Re: Randomizing an Array?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gavin K. (Guest)
on 2006-12-22 22:16
(Received via mailing list)
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.)
This topic is locked and can not be replied to.