// /** // * A sufficient Pseudo-Random-Number-Generators (PRNG) of the Xorshift family // * // * For single threaded operations the PRNG provided by `R` are prefered. But they // * are _not_ thread save. The following is a simple PRNG usable in a multi-threaded // * application. // * // * See TODO: ...https://en.wikipedia.org/wiki/Xorshift // * SchachHoernchen // */ // #ifndef INCLUDE_GUARD_RANDOM_H // #define INCLUDE_GUARD_RANDOM_H // #include // uint32_t, uint64_t // static inline uint64_t rot64(uint64_t val, int shift) { // return (val << shift) | (val >> (64 - shift)); // } // // PRNG of the Xorshift family // // @note the least significant 32 bits are not reliable, use most significant 32 bits // static inline uint64_t rand_u64(uint64_t seed[4]) { // uint64_t e = seed[0] - rot64(seed[1], 7); // seed[0] = seed[1] ^ rot64(seed[1], 13); // seed[1] = seed[2] + rot64(seed[3], 37); // seed[2] = seed[3] + e; // seed[3] = e + seed[0]; // return seed[3]; // } // static inline double unif_rand_u64(uint64_t seed[4]) { // return ((double)(rand_u64(seed) >> 32)) / (double)(-(uint32_t)1); // } // #endif