Skip to content

Commit d706302

Browse files
committed
xorshift
1 parent afa0e3d commit d706302

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

marathon/rand_xorshift.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <cstdint>
2+
3+
struct Rand {
4+
private:
5+
constexpr static double R = 1.0 / 0xffffffff;
6+
uint64_t x;
7+
8+
public:
9+
Rand(uint64_t seed = 88172645463325252ull) : x(seed) {}
10+
11+
inline uint64_t nextULong() { // [0, 2^64)
12+
x ^= x << 7ull;
13+
x ^= x >> 9ull;
14+
return x;
15+
}
16+
17+
inline uint32_t nextUInt(uint32_t r) { // [0, r)
18+
return ((nextULong() >> 32ull) * r) >> 32ull;
19+
}
20+
21+
inline uint32_t nextUInt(uint32_t l, uint32_t r) { // [l, r)
22+
return l + nextUInt(r - l);
23+
}
24+
25+
inline double nextDouble() { // [0.0, 1.0]
26+
return ((uint32_t)nextULong()) * R;
27+
}
28+
};

marathon/template.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool chmax(Tp& a, const Tp& b) {
108108
}
109109

110110
#include "/home/tsutaj/Documents/compro/cpp_library/marathon/timer.cpp"
111-
#include "/home/tsutaj/Documents/compro/cpp_library/marathon/rand.cpp"
111+
#include "/home/tsutaj/Documents/compro/cpp_library/marathon/rand_xorshift.cpp"
112112
Rand rnd(35023503980LL);
113113
Timer timer;
114114
using Answer = vector<int>; // TODO
@@ -134,5 +134,6 @@ int main() {
134134
timer.setStart();
135135
input();
136136
solve();
137+
fprintf(stderr, "end time = %.3f\n", timer.getTime());
137138
return 0;
138139
}

0 commit comments

Comments
 (0)