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

No comments:

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels