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
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
using namespace std;
class Tester {
private:
vector<vector<int>> old_results;
public:
void test(int seed, int seq_len);
};
void Tester::test(int seed, int seq_len) {
// re-seed
srand(seed);
// output new sequence
vector<int> results;
cout << old_results.size() << "). seq for seed(" << seed << ") =";
for(int i = 0; i < seq_len; ++i) {
int val = (rand() % 100 + 1);
results.push_back(val); // remembering the values
cout << " " << val;
}
// check results against previous runs
auto iter = find(old_results.cbegin(), old_results.cend(), results);
if(iter != old_results.cend()) { // if we find matching results, report the fact
cout << " - same as result set " << distance(old_results.cbegin(), iter);
}
cout << "\n\n";
// remember latest results
old_results.push_back(results);
}
int main() {
const int seeds[] = {123, 123, 123, 42, 180, 180, 42, 123};
const int num_seeds = sizeof(seeds)/sizeof(seeds[0]);
const int seq_len = 8;
Tester tester;
for(int i = 0; i < num_seeds; ++i) {
tester.test(seeds[i], seq_len);
}
return 0;
}
|