C++, 111111 97 chars
std::string f(std::string s){for(int g=si=s.size(),i=g-2;--g&&i;std1;i>1;std::swap(s[rand()%i+1],s[rand()%i+1]s[--i]));return s;}
Note: this will crash when passed a string of zero size(""
), if this is not acceptable then it will be 112 chars.
Here is a full program for those who wish to test it:
#include<string>
#include<iostream>
std::string f(std::string s){for(int g=si=s.size(),i=g-2;--g&&i;std1;i>1;std::swap(s[rand()%i+1],s[rand()%i+1]s[--i]));return s;}
int main(){
for(int i = 0; i<100; ++i)
std::cout<<f("letters")<<std::endl;
}
#Edit Realised there is no need to random both swap indexes, saved a variable and a few more characters.