// 01-02: sample // 03-08: equal prob of size 1, 10, 50, 100, 250, 500 // 09-13: random prob of size 10, 50, 100, 250, 500 // 14-16: random capped prob of size 500 #include #include #include #include #include #include #include #include using namespace std; const string probname = "rm16-password"; random_device rd; default_random_engine e1(rd()); int rand_int(int low, int high) { uniform_int_distribution uniform_dist(low, high); return uniform_dist(e1); } string rand_str(int len) { string s; for (int i = 0; i < len; i++) { int c = rand_int(0,2); if (c == 0) { int x = rand_int(0, 25); s += (char)('a' + x); } else if (c == 1) { int x = rand_int(0, 25); s += (char)('A' + x); } else { int x = rand_int(0, 9); s += (char)('0' + x); } } return s; } void gen_rand(int n, int c) { ostringstream oss; oss << probname << "-" << setw(2) << setfill('0') << c << ".in"; ofstream os(oss.str().c_str()); os << n << endl; int total = 0; string pw[500]; int prob[500]; for (int i = 0; i < n; i++) { do { pw[i] = rand_str(rand_int(8,12)); } while (find(pw, pw+i, pw[i]) != pw+i); prob[i] = (i < n-1) ? rand_int(1, 10000-total-(n-i-1)) : 10000 - total; total += prob[i]; } shuffle(prob, prob+n, e1); for (int i = 0; i < n; i++) { os << pw[i] << ' ' << prob[i]/10000 << '.' << setw(4) << setfill('0') << prob[i] % 10000 << endl; } assert(total == 10000); } void gen_rand_cap(int n, int c) { ostringstream oss; oss << probname << "-" << setw(2) << setfill('0') << c << ".in"; ofstream os(oss.str().c_str()); os << n << endl; int total = 0; string pw[500]; int prob[500]; for (int i = 0; i < n; i++) { do { pw[i] = rand_str(rand_int(8,12)); } while (find(pw, pw+i, pw[i]) != pw+i); // cap it so it can't be too high for one of them prob[i] = (i < n-1) ? rand_int(1, min(10000-total-(n-i-1), 15000/n)) : 10000 - total; total += prob[i]; } shuffle(prob, prob+n, e1); for (int i = 0; i < n; i++) { os << pw[i] << ' ' << prob[i]/10000 << '.' << setw(4) << setfill('0') << prob[i] % 10000 << endl; } assert(total == 10000); } void gen_equal(int n, int c) { ostringstream oss; oss << probname << "-" << setw(2) << setfill('0') << c << ".in"; ofstream os(oss.str().c_str()); os << n << endl; assert(10000 % n == 0); for (int i = 0; i < n; i++) { string pw[500]; int prob[500]; do { pw[i] = rand_str(rand_int(8,12)); } while (find(pw, pw+i, pw[i]) != pw+i); prob[i] = 10000/n; os << pw[i] << ' ' << prob[i]/10000 << '.' << setw(4) << setfill('0') << prob[i] % 10000 << endl; } } int main() { int c = 3; gen_equal(1, c++); gen_equal(10, c++); gen_equal(50, c++); gen_equal(100, c++); gen_equal(250, c++); gen_equal(500, c++); gen_rand(10, c++); gen_rand(50, c++); gen_rand(100, c++); gen_rand(250, c++); gen_rand(500, c++); gen_rand_cap(500, c++); gen_rand_cap(500, c++); gen_rand_cap(500, c++); }