Forum: Ruby randomizing a simple array of strings

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.
Michael G. (Guest)
on 2006-04-27 00:37
(Received via mailing list)
OK, this is pretty bad for a CS grad to ask, but my brain is worn out
today.

I building a list of words (storing them in an Array).

I want to randomize the order.

Can anyone point me to a tutorial or common algorithm for that?

Thank you,

Michael G.
Kirk H. (Guest)
on 2006-04-27 00:50
(Received via mailing list)
On Wednesday 26 April 2006 2:36 pm, Michael G. wrote:

> I building a list of words (storing them in an Array).
>
> I want to randomize the order.
>
> Can anyone point me to a tutorial or common algorithm for that?

@array.sort_by {rand}


Kirk H.
Michael G. (Guest)
on 2006-04-27 00:53
(Received via mailing list)
Holy crap.  That is beautiful.

Thank you so much.
Matthew M. (Guest)
on 2006-04-27 01:37
(Received via mailing list)
> Holy crap.  That is beautiful.

+1.
This topic is locked and can not be replied to.