str_shuffle
-
There is no native function to shuffle the characters of a string in Ruby, but this can be accomplished easy enough by performing the following:
String#splitthe string on every characterArray#sort_bythe characters at randomArray#jointhe characters back into a single string
PHP
$result = str_shuffle('Hello'); var_export($result); // => 'llHoe'
Ruby
p "Hello".split("").sort_by { rand }.join # => "loHle"
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

