23 return int(low + (rand() /
double(RAND_MAX)) * (high - low) + 0.5);
29 for (
int i = 0; i < len; ++i)
30 (*s)[i] = (char)
random(32, 127);
34 const int N = 20 * 1000 * 1000;
37 char** commands =
new char*[N];
38 pair<uint64_t, int>* hashes =
new pair<uint64_t, int>[N];
40 srand((
int)time(NULL));
42 for (
int i = 0; i < N; ++i) {
47 sort(hashes, hashes + N);
49 int num_collisions = 0;
50 for (
int i = 1; i < N; ++i) {
51 if (hashes[i - 1].first == hashes[i].first) {
52 if (strcmp(commands[hashes[i - 1].second],
53 commands[hashes[i].second]) != 0) {
54 printf(
"collision!\n string 1: '%s'\n string 2: '%s'\n",
55 commands[hashes[i - 1].second],
56 commands[hashes[i].second]);
61 printf(
"\n\n%d collisions after %d runs\n", num_collisions, N);