-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_usernames.cpp
62 lines (48 loc) · 1.48 KB
/
gen_usernames.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Author: Dustin Sallings.
Original copy: https://gist.github.com/dustin/1189242 */
#include <string>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include "bloom_filter.hpp"
using namespace std;
string words("abcdefghijklmnopqrstuvwxyz"
"0123456789");
const int report_every(100000);
const int max_permutations(1000);
int main(int argc, char **argv) {
if (argc < 2) {
cerr << "Need to tell me how many you want." << endl;
exit(64); // EX_USAGE
}
srand(718472382); // Now with determinism.
int todo(atoi(argv[1]));
bloom_filter filter(todo, 0.0001, time(NULL));
int dups(0);
int since(0);
for (int done = 0; done < todo;) {
int length = (rand() % 6) + 6;
random_shuffle(words.begin(), words.end());
string word(words.substr(0, length));
int permutations = rand() % max_permutations;
for (int j = 0; j < permutations && done < todo; ++j) {
if (!next_permutation(word.begin(), word.end())) {
break;
}
if (filter.contains(word)) {
++dups;
} else {
++done;
filter.insert(word);
cout << word << "\n";
}
if (done % report_every == 0 && dups > 0) {
cerr << dups << " dups in the last " << since << endl;
dups = 0;
since = 0;
}
++since;
}
}
return 0;
}