#include<iostream> #include<algorithm> #include<vector> #include<fstream> #include<ctime> std::ofstream ofs("result.txt"); std::vector<char> table; class Random{ public: Random(){ srand(static_cast<unsigned int>(time(NULL))); } unsigned int operator()(unsigned int m){ double a = static_cast<double>(rand())/static_cast<double>(RAND_MAX); return static_cast<unsigned int>(a*m); } }; void make(){ char c = 'A'; for(int i=0;i<30;i++){ if(!isalpha(c)) break; table.push_back(c); c++; } c = 'a'; for(int i=0;i<30;i++){ if(!isalpha(c)) break; table.push_back(c); c++; } c = '0'; for(int i=0;i<10;i++){ table.push_back(c); c++; } } int main(void){ std::cout << "桁数を入力" << std::endl; int n; table.clear(); make(); Random r; std::cin >> n; std::random_shuffle(table.begin(),table.end(),r); std::string res; for(int i=0;i<n;i++){ res += table[i]; } ofs << res; std::cout << "result.txtに書き込みました" << std::endl; return 0; }
どうせ昔のものに戻すので一時的なpasswd作成コード
for文の回す回数は26以上なら良かったので適当