-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_3_22.cpp
61 lines (47 loc) · 1.57 KB
/
set_3_22.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
#include <iostream>
#include <thread>
#include <chrono>
#include <random>
#include <ctime>
#include "mt19937.hpp"
using namespace std::chrono_literals;
namespace {
std::chrono::seconds random_sleep_minimum = 5s;// 40s;
std::chrono::seconds random_sleep_maximum = 40s;// 1000s;
std::mt19937 gen((std::random_device())());
}
std::chrono::seconds random_sleep_time() {
std::uniform_int_distribution<int> dist(random_sleep_minimum.count(), random_sleep_maximum.count());
int t = dist(gen);
return std::chrono::seconds(t);
}
void random_sleep() {
auto t = random_sleep_time();
std::cout << "sleeping for " << t.count() << "s" << std::endl;
std::this_thread::sleep_for(t);
}
int current_timestamp() {
return (int)std::time(nullptr);
}
int main() {
random_sleep();
auto ct = current_timestamp();
std::cout << "seed: " << ct << std::endl;
mt19937 my_random(ct);
random_sleep();
uint32_t random_first_value = my_random.extract_number();
std::cout << "random first value: " << random_first_value << std::endl;
auto now = current_timestamp();
mt19937 test_random;
for (int i = now - (random_sleep_maximum.count()); i < now; i += 1) {
auto test_seed = i;
test_random.seed_mt(test_seed);
uint32_t test_value = test_random.extract_number();
if (test_value == random_first_value) {
auto diff = now - test_seed;
std::cout << "Found seed: " << test_seed << std::endl;
std::cout << "Seed generated " << diff << "s ago" << std::endl;
}
}
return 0;
}