Open Zibri opened 5 years ago
And check my optimized code at https://github.com/zibri/rand2
Or also:
#ifndef ZIBRI192_H
#define ZIBRI192_H
/* Modified by D. Lemire, August 2017 */
#include "splitmix64.h"
#include <stdint.h>
// state for zibri192
uint64_t zibri192_s[3];
static inline uint64_t rotr(const uint64_t x, int k) {
return (x >> k) | (x << (64 - k));
}
// call this one before calling zibri192
static inline void zibri192_seed(uint64_t seed) {
zibri192_s[0] = splitmix64_stateless(seed);
zibri192_s[1] = splitmix64_stateless(seed + 1);
zibri192_s[2] = splitmix64_stateless(seed + 2);
}
// returns random number, modifies zibri192_s
static inline uint64_t zibri192(void) {
const uint64_t s0 = zibri192_s[0];
const uint64_t s1 = zibri192_s[1];
const uint64_t s2 = zibri192_s[2];
zibri192_s[0] = rotr(s0 + s1 + s2,16);
zibri192_s[1] = s0;
zibri192_s[2] = s1;
return zibri192_s[0];
}
#endif // ZIBRI192_H
Thank you.
is the fastest so far...