01.04.2012, 14:32
That would be my solution
- 1. Get the length of the string
- 2. Get an random index with the length, random(length)
- 3. Saving this char in a variable
- 4. Shifting the other character to the right to free the left most position and fill the position where we took our char from
- 5. Now we put the char in his new position, the left most
- 6. Repeating step 2 - 5 and decreasing the length by one and increasing the start position (where we put the char in)
- 7. Repeating step 2 - 6 till the length is lower than 2 (its nonsense to swap 1 char with itself)