Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Sunday, November 9, 2008

Ruby - Randomize arrays and strings


Randomize the elements of an array:


random_array = my_array.sort_by{rand}

Randomize a string (jumble a given word):

jumbled_word = word.split("").sort_by{rand}.join

1 comments:

Jen said...

The blog is helpfull...
visit also asp.net [c#]

About Me

My Photo
Doug Sparling
Rails programmer by day, .NET programmer by night (yeah, yeah, I know, that's backwards - consider me lucky, I do) with a passion for Javascript, jQuery, Ajax, and Flex.
View my complete profile

Blog Archive

Labels