#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <algorithm>
#include <iterator>
int main()
{
// the hard, inefficient way
{
enum { N = 7, M = 13 } ;
char dest[N][M] = { "zero", "one", "two", "three", "four", "five", "six" } ;
std::srand( std::time(nullptr) ) ;
for( int i = N-1 ; i > 0 ; --i ) // fisher yates shuffle
{
const int pos = std::rand() % (i+1) ;
char temp[M] ;
std::strcpy( temp, dest[pos] ) ;
std::strcpy( dest[pos], dest[i] ) ;
std::strcpy( dest[i], temp ) ;
}
for( const char* cstr : dest ) std::cout << cstr << ' ' ;
std::cout << '\n' ;
}
// the simple, efficient way
{
enum { N = 7 } ;
std::string dest[N] = { "zero", "one", "two", "three", "four", "five", "six" } ;
std::srand( std::time(nullptr) ) ; // if it has not already been done
std::random_shuffle( std::begin(dest), std::end(dest) ) ;
for( const std::string& str : dest ) std::cout << str << ' ' ;
std::cout << '\n' ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGl0ZXJhdG9yPgoKaW50IG1haW4oKQp7CiAgICAvLyB0aGUgaGFyZCwgaW5lZmZpY2llbnQgd2F5CiAgICB7CiAgICAgICAgZW51bSB7IE4gPSA3LCBNID0gMTMgfSA7CiAgICAgICAgY2hhciBkZXN0W05dW01dID0geyAiemVybyIsICJvbmUiLCAidHdvIiwgInRocmVlIiwgImZvdXIiLCAiZml2ZSIsICJzaXgiIH0gOwoKICAgICAgICBzdGQ6OnNyYW5kKCBzdGQ6OnRpbWUobnVsbHB0cikgKSA7CgogICAgICAgIGZvciggaW50IGkgPSBOLTEgOyBpID4gMCA7IC0taSApIC8vIGZpc2hlciB5YXRlcyBzaHVmZmxlCiAgICAgICAgewogICAgICAgICAgICBjb25zdCBpb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