-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathruntime_notes.cpp
More file actions
77 lines (62 loc) · 2.12 KB
/
Copy pathruntime_notes.cpp
File metadata and controls
77 lines (62 loc) · 2.12 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "runtime_notes.h"
#include <cstdint>
#include <ctime>
#include <iostream>
namespace {
struct SpecialWindow {
int start_day;
int end_day;
};
// Sorted by start_day and non-overlapping; is_special_period() relies on it
constexpr SpecialWindow SPECIAL_WINDOWS[] = {
{20902, 20906}, // 2027-03-25 .. 2027-03-29
{21287, 21291}, // 2028-04-13 .. 2028-04-17
{21637, 21641}, // 2029-03-29 .. 2029-04-02
{22022, 22026}, // 2030-04-18 .. 2030-04-22
{22379, 22383}, // 2031-04-10 .. 2031-04-14
{22729, 22733}, // 2032-03-25 .. 2032-03-29
{23114, 23118}, // 2033-04-14 .. 2033-04-18
{23471, 23475}, // 2034-04-06 .. 2034-04-10
{23821, 23825}, // 2035-03-22 .. 2035-03-26
};
bool is_special_period(const int unix_day) {
constexpr size_t window_count = sizeof(SPECIAL_WINDOWS) / sizeof(SPECIAL_WINDOWS[0]);
constexpr int first_day = SPECIAL_WINDOWS[0].start_day;
constexpr int last_day = SPECIAL_WINDOWS[window_count - 1].end_day;
if (unix_day < first_day || unix_day > last_day) {
return false;
}
for (size_t i = 0; i < window_count; ++i) {
const auto& window = SPECIAL_WINDOWS[i];
if (unix_day < window.start_day) {
return false;
}
if (unix_day <= window.end_day) {
return true;
}
}
return false;
}
} // namespace
void maybe_log_runtime_note() {
const std::time_t now = std::time(nullptr);
// Keep this UTC-based: unix_day is days since the Unix epoch in UTC
const int unix_day = static_cast<int>(now / 86400);
if (!is_special_period(unix_day)) {
return;
}
// Cheap deterministic pseudo-random choice based on current second
uint32_t x = static_cast<uint32_t>(now);
x ^= x >> 16;
x *= 0x7feb352dU;
x ^= x >> 15;
x *= 0x846ca68bU;
x ^= x >> 16;
// ~2% chance
if ((x % 100) >= 2) {
return;
}
static constexpr const char* notes[] = {"comparison is an illusion", "perception is biased", "perfect sync is a myth", "the truth is somewhere between", "you are comparing yourself"};
constexpr size_t note_count = sizeof(notes) / sizeof(notes[0]);
std::cout << "Parallax: " << notes[(x / 100) % note_count] << '\n';
}