Skip to main content
deleted 30 characters in body
Source Link

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.

C++, 111 chars

std::string f(std::string s){for(int g=s.size(),i=g-2;--g&&i;std::swap(s[rand()%i+1],s[rand()%i+1]));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=s.size(),i=g-2;--g&&i;std::swap(s[rand()%i+1],s[rand()%i+1]));return s;}

int main(){
    for(int i = 0; i<100; ++i)
    std::cout<<f("letters")<<std::endl;
}

C++, 111 97 chars

std::string f(std::string s){for(int i=s.size()-1;i>1;std::swap(s[rand()%i+1],s[--i]));return s;}

Here is a full program for those who wish to test it:

#include<string>
#include<iostream>

std::string f(std::string s){for(int i=s.size()-1;i>1;std::swap(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.

Source Link

C++, 111 chars

std::string f(std::string s){for(int g=s.size(),i=g-2;--g&&i;std::swap(s[rand()%i+1],s[rand()%i+1]));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=s.size(),i=g-2;--g&&i;std::swap(s[rand()%i+1],s[rand()%i+1]));return s;}

int main(){
    for(int i = 0; i<100; ++i)
    std::cout<<f("letters")<<std::endl;
}