// Generate a random sequence of characters: // 0-9 // A-Z // a-z // -,_ #include #include #include int main(int argc, char * argv[]) { // Default length: 16 // Minimum length: 1 int length; if(argc > 1) length = std::atoi(argv[1]); if(length < 1) length = 16; // Seed the pseudo-random generator with some actual randomness std::mt19937 prand; { std::random_device rd; prand.seed( rd() ); } // Generate random integers in the range [0, 63] std::uniform_int_distribution range(0, 63); for(int i = 0; i < length; ++i) { // Transform the integer into acceptable characters char next = range(prand); // 0-9 if(next < 10) std::cout << char(next + 48); // A-Z else if(next < 36) std::cout << char(next + 55); // a-z else if(next < 62) std::cout << char(next + 61); // - else if(next < 63) std::cout << '-'; // _ else std::cout << '_'; } std::cout << std::endl; return 0; }