Ask coding questions

← Back to all posts
How would I shuffle a string or mix up its characters?
JoshuaKing1 (7)

For example, 'text' might turn into 'xtet'
I know how to do an array but nothing else.

Answered by theangryepicbanana (1305) [earned 5 cycles]
View Answer
theangryepicbanana (1305)

Try '0587'.chars.shuffle.join. This creates an array with each character in the string, shuffles them, and then joins them together to make a string. (btw if this answered your question, mark this as the best answer)