// From: http://scv.bu.edu/examples/random_numbers/xoroshiro128_plus/CPP/ // COMPILE WITH AT LEAST C++11 // e.g. gcc version 4.9.2: g++ -std=c++0x // gcc version 5.3.0: g++ -std=c++11 or -std=c++14 // intel version 2015 or 2016: icc -std=c++11 #ifndef XOROSHIRO128_PLUS_H #define XOROSHIRO128_PLUS_H #include #include #include #include namespace xoroshiro128_plus { class Xoroshiro128_plus { public: // The seed. uint64_t seed_0,seed_1 ; // Constructor for STL iterators. // call with Xoroshiro128_plus(my_vec.begin(), my_vec.end()) // Since this is templated it needs to be implemented here. template Xoroshiro128_plus(ForwardIterator begin, ForwardIterator end) { if (end-begin < 2) throw "Need 2 elements to initialize the RNG." ; int i = 0 ; seed_0 = *begin; ++begin; seed_1 = *begin; } // Constructor for a seed in an array. Xoroshiro128_plus(uint64_t seed_[]) ; // Return the total number of bytes in the seed int get_seed_bytes() ; // Return the number of elements in the seed. int get_seed_length() ; // Get the next uint64 random number. uint64_t next_uint64() ; // get the next double. double next_double() ; // get the next float. float next_float() ; // jump ahead by 2^64 and return a new // generator. Xoroshiro128_plus jump() ; // copy the RNG object. Xoroshiro128_plus(const Xoroshiro128_plus &obj) ; // Static method to get some random bytes from hardware static void get_random_seed(uint64_t dest[]) ; private: // rotate left. static inline uint64_t rotl(const uint64_t x, int k); // The number of elements in the seed static const int seed_length ; inline uint64_t next() ; }; } #endif /* XOROSHIRO128_PLUS_H */