# Randomizing a simple array of strings

**URL:** <https://www.ruby-forum.com/t/randomizing-a-simple-array-of-strings/58886>\
**Category:** Ruby\
**Created:** [April 26, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/randomizing-a-simple-array-of-strings/58886 "2006-04-26T22:37:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 26, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/randomizing-a-simple-array-of-strings/58886/1 "2006-04-26T22:37:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 26, 2006, 10:50pm UTC](https://www.ruby-forum.com/t/randomizing-a-simple-array-of-strings/58886/2 "2006-04-26T22:50:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 26, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/randomizing-a-simple-array-of-strings/58886/3 "2006-04-26T22:53:37Z")

</div>

Holy crap. That is beautiful.

Thank you so much.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [April 26, 2006, 11:37pm UTC](https://www.ruby-forum.com/t/randomizing-a-simple-array-of-strings/58886/4 "2006-04-26T23:37:36Z")

</div>

> Holy crap. That is beautiful.

+1.
