# Re: Randomizing an Array?

**URL:** <https://www.ruby-forum.com/t/re-randomizing-an-array/80249>\
**Category:** Ruby\
**Created:** [December 22, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/re-randomizing-an-array/80249 "2006-12-22T20:44:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [December 22, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/re-randomizing-an-array/80249/1 "2006-12-22T20:44:21Z")

</div>

From: jwcooper [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

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

randomized = my\_array.sort\_by{ rand }

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [December 22, 2006, 9:10pm UTC](https://www.ruby-forum.com/t/re-randomizing-an-array/80249/2 "2006-12-22T21:10:28Z")

</div>

Gavin K. wrote:

> From: jwcooper [[mailto:removed\_email\_address@domain.invalid](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!

I need to keep reminding myself that there is always a simpler solution  
with Ruby. I still have the Java mindset.
