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.
2c80e1b0837eec76d38d4f7fa1c15e87?d=identicon&s=25 Michael Gorsuch (Guest)
on 2006-04-26 22: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 Gorsuch
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 Kirk Haines (Guest)
on 2006-04-26 22:50
(Received via mailing list)
On Wednesday 26 April 2006 2:36 pm, Michael Gorsuch 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 Haines
2c80e1b0837eec76d38d4f7fa1c15e87?d=identicon&s=25 Michael Gorsuch (Guest)
on 2006-04-26 22:53
(Received via mailing list)
Holy crap.  That is beautiful.

Thank you so much.
81d609425e306219d54d793a0ad98bce?d=identicon&s=25 Matthew Moss (Guest)
on 2006-04-26 23:37
(Received via mailing list)
> Holy crap.  That is beautiful.

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