-
Notifications
You must be signed in to change notification settings - Fork 0
/
lehmer64.h
30 lines (24 loc) · 851 Bytes
/
lehmer64.h
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
#ifndef LEHMER64_H
#define LEHMER64_H
#include "splitmix64.h"
static __uint128_t g_lehmer64_state;
/**
* D. H. Lehmer, Mathematical methods in large-scale computing units.
* Proceedings of a Second Symposium on Large Scale Digital Calculating
* Machinery;
* Annals of the Computation Laboratory, Harvard Univ. 26 (1951), pp. 141-146.
*
* P L'Ecuyer, Tables of linear congruential generators of different sizes and
* good lattice structure. Mathematics of Computation of the American
* Mathematical
* Society 68.225 (1999): 249-260.
*/
static inline void lehmer64_seed(uint64_t seed) {
g_lehmer64_state = (((__uint128_t)splitmix64_stateless(seed)) << 64) +
splitmix64_stateless(seed + 1);
}
static inline uint64_t lehmer64(void) {
g_lehmer64_state *= U64_C(0xda942042e4dd58b5);
return g_lehmer64_state >> 64;
}
#endif