-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmeta_random.hpp
39 lines (32 loc) · 1.04 KB
/
meta_random.hpp
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
#ifndef META_RANDOM_HPP
#define META_RANDOM_HPP
#include <limits>
namespace snowapril {
constexpr int RandomSeed(void) {
return '0' * -40271 + // offset accounting for digits' ANSI offsets
__TIME__[7] * 1 +
__TIME__[6] * 10 +
__TIME__[4] * 60 +
__TIME__[3] * 600 +
__TIME__[1] * 3600 +
__TIME__[0] * 36000;
};
template <unsigned int a,
unsigned int c,
unsigned int seed,
unsigned int Limit>
struct LinearCongruentialEngine {
enum { value = (a * LinearCongruentialEngine<a, c - 1, seed, Limit>::value + c) % Limit };
};
template <unsigned int a,
unsigned int seed,
unsigned int Limit>
struct LinearCongruentialEngine<a, 0, seed, Limit> {
enum { value = (a * seed) % Limit };
};
template <int N, int Limit>
struct MetaRandom {
enum { value = LinearCongruentialEngine<16807, N, RandomSeed(), Limit>::value };
};
}
#endif