diff --git a/extern/pcg_extras.hpp b/extern/pcg_extras.hpp index 05e8cf9..ad05d78 100644 --- a/extern/pcg_extras.hpp +++ b/extern/pcg_extras.hpp @@ -33,17 +33,17 @@ #ifndef PCG_EXTRAS_HPP_INCLUDED #define PCG_EXTRAS_HPP_INCLUDED 1 +#include #include #include #include #include -#include -#include #include +#include +#include +#include #include #include -#include -#include #ifdef __GNUC__ #include @@ -78,28 +78,25 @@ namespace pcg_extras { typedef __uint128_t pcg128_t; } -#define PCG_128BIT_CONSTANT(high,low) \ - ((pcg_extras::pcg128_t(high) << 64) + low) +#define PCG_128BIT_CONSTANT(high, low) ((pcg_extras::pcg128_t(high) << 64) + low) #else #include "pcg_uint128.hpp" - namespace pcg_extras { - typedef pcg_extras::uint_x4 pcg128_t; - } - #define PCG_128BIT_CONSTANT(high,low) \ - pcg_extras::pcg128_t(high,low) - #define PCG_EMULATED_128BIT_MATH 1 +namespace pcg_extras { + typedef pcg_extras::uint_x4 pcg128_t; +} +#define PCG_128BIT_CONSTANT(high, low) pcg_extras::pcg128_t(high, low) +#define PCG_EMULATED_128BIT_MATH 1 #endif - namespace pcg_extras { -/* - * We often need to represent a "number of bits". When used normally, these - * numbers are never greater than 128, so an unsigned char is plenty. - * If you're using a nonstandard generator of a larger size, you can set - * PCG_BITCOUNT_T to have it define it as a larger size. (Some compilers - * might produce faster code if you set it to an unsigned int.) - */ + /* + * We often need to represent a "number of bits". When used normally, these + * numbers are never greater than 128, so an unsigned char is plenty. + * If you're using a nonstandard generator of a larger size, you can set + * PCG_BITCOUNT_T to have it define it as a larger size. (Some compilers + * might produce faster code if you set it to an unsigned int.) + */ #ifndef PCG_BITCOUNT_T typedef uint8_t bitcount_t; @@ -107,25 +104,23 @@ namespace pcg_extras { typedef PCG_BITCOUNT_T bitcount_t; #endif -/* - * C++ requires us to be able to serialize RNG state by printing or reading - * it from a stream. Because we use 128-bit ints, we also need to be able - * ot print them, so here is code to do so. - * - * This code provides enough functionality to print 128-bit ints in decimal - * and zero-padded in hex. It's not a full-featured implementation. - */ + /* + * C++ requires us to be able to serialize RNG state by printing or reading + * it from a stream. Because we use 128-bit ints, we also need to be able + * ot print them, so here is code to do so. + * + * This code provides enough functionality to print 128-bit ints in decimal + * and zero-padded in hex. It's not a full-featured implementation. + */ template - std::basic_ostream& - operator<<(std::basic_ostream& out, pcg128_t value) - { + std::basic_ostream& operator<<(std::basic_ostream& out, pcg128_t value) { auto desired_base = out.flags() & out.basefield; bool want_hex = desired_base == out.hex; if (want_hex) { uint64_t highpart = uint64_t(value >> 64); - uint64_t lowpart = uint64_t(value); + uint64_t lowpart = uint64_t(value); auto desired_width = out.width(); if (desired_width > 16) { out.width(desired_width - 16); @@ -148,7 +143,7 @@ namespace pcg_extras { constexpr size_t MAX_CHARS_128BIT = 40; char buffer[MAX_CHARS_128BIT]; - char* pos = buffer+sizeof(buffer); + char* pos = buffer + sizeof(buffer); *(--pos) = '\0'; constexpr auto BASE = pcg128_t(10ULL); do { @@ -156,15 +151,13 @@ namespace pcg_extras { auto mod = uint32_t(value - (div * BASE)); *(--pos) = '0' + char(mod); value = div; - } while(value != pcg128_t(0ULL)); + } while (value != pcg128_t(0ULL)); return out << pos; } template - std::basic_istream& - operator>>(std::basic_istream& in, pcg128_t& value) - { - typename std::basic_istream::sentry s(in); + std::basic_istream& operator>>(std::basic_istream& in, pcg128_t& value) { + typename std::basic_istream::sentry s(in); if (!s) return in; @@ -173,7 +166,7 @@ namespace pcg_extras { pcg128_t current(0ULL); bool did_nothing = true; bool overflow = false; - for(;;) { + for (;;) { CharT wide_ch = in.get(); if (!in.good()) break; @@ -184,7 +177,7 @@ namespace pcg_extras { } did_nothing = false; pcg128_t digit(uint32_t(ch - '0')); - pcg128_t timesbase = current*BASE; + pcg128_t timesbase = current * BASE; overflow = overflow || timesbase < current; current = timesbase + digit; overflow = overflow || current < digit; @@ -201,24 +194,20 @@ namespace pcg_extras { return in; } -/* - * Likewise, if people use tiny rngs, we'll be serializing uint8_t. - * If we just used the provided IO operators, they'd read/write chars, - * not ints, so we need to define our own. We *can* redefine this operator - * here because we're in our own namespace. - */ + /* + * Likewise, if people use tiny rngs, we'll be serializing uint8_t. + * If we just used the provided IO operators, they'd read/write chars, + * not ints, so we need to define our own. We *can* redefine this operator + * here because we're in our own namespace. + */ template - std::basic_ostream& - operator<<(std::basic_ostream&out, uint8_t value) - { + std::basic_ostream& operator<<(std::basic_ostream& out, uint8_t value) { return out << uint32_t(value); } template - std::basic_istream& - operator>>(std::basic_istream& in, uint8_t& target) - { + std::basic_istream& operator>>(std::basic_istream& in, uint8_t& target) { uint32_t value = 0xdecea5edU; in >> value; if (!in && value == 0xdecea5edU) @@ -231,40 +220,34 @@ namespace pcg_extras { return in; } -/* Unfortunately, the above functions don't get found in preference to the - * built in ones, so we create some more specific overloads that will. - * Ugh. - */ + /* Unfortunately, the above functions don't get found in preference to the + * built in ones, so we create some more specific overloads that will. + * Ugh. + */ - inline std::ostream& operator<<(std::ostream& out, uint8_t value) - { - return pcg_extras::operator<< (out, value); + inline std::ostream& operator<<(std::ostream& out, uint8_t value) { + return pcg_extras::operator<<(out, value); } - inline std::istream& operator>>(std::istream& in, uint8_t& value) - { - return pcg_extras::operator>> (in, value); + inline std::istream& operator>>(std::istream& in, uint8_t& value) { + return pcg_extras::operator>>(in, value); } + /* + * Useful bitwise operations. + */ + /* + * XorShifts are invertable, but they are someting of a pain to invert. + * This function backs them out. It's used by the whacky "inside out" + * generator defined later. + */ -/* - * Useful bitwise operations. - */ - -/* - * XorShifts are invertable, but they are someting of a pain to invert. - * This function backs them out. It's used by the whacky "inside out" - * generator defined later. - */ - - template - inline itype unxorshift(itype x, bitcount_t bits, bitcount_t shift) - { - if (2*shift >= bits) { + template inline itype unxorshift(itype x, bitcount_t bits, bitcount_t shift) { + if (2 * shift >= bits) { return x ^ (x >> shift); } - itype lowmask1 = (itype(1U) << (bits - shift*2)) - 1; + itype lowmask1 = (itype(1U) << (bits - shift * 2)) - 1; itype highmask1 = ~lowmask1; itype top1 = x; itype bottom1 = x & lowmask1; @@ -278,36 +261,32 @@ namespace pcg_extras { return top1 | bottom2; } -/* - * Rotate left and right. - * - * In ideal world, compilers would spot idiomatic rotate code and convert it - * to a rotate instruction. Of course, opinions vary on what the correct - * idiom is and how to spot it. For clang, sometimes it generates better - * (but still crappy) code if you define PCG_USE_ZEROCHECK_ROTATE_IDIOM. - */ + /* + * Rotate left and right. + * + * In ideal world, compilers would spot idiomatic rotate code and convert it + * to a rotate instruction. Of course, opinions vary on what the correct + * idiom is and how to spot it. For clang, sometimes it generates better + * (but still crappy) code if you define PCG_USE_ZEROCHECK_ROTATE_IDIOM. + */ - template - inline itype rotl(itype value, bitcount_t rot) - { + template inline itype rotl(itype value, bitcount_t rot) { constexpr bitcount_t bits = sizeof(itype) * 8; constexpr bitcount_t mask = bits - 1; #if PCG_USE_ZEROCHECK_ROTATE_IDIOM return rot ? (value << rot) | (value >> (bits - rot)) : value; #else - return (value << rot) | (value >> ((- rot) & mask)); + return (value << rot) | (value >> ((-rot) & mask)); #endif } - template - inline itype rotr(itype value, bitcount_t rot) - { + template inline itype rotr(itype value, bitcount_t rot) { constexpr bitcount_t bits = sizeof(itype) * 8; constexpr bitcount_t mask = bits - 1; #if PCG_USE_ZEROCHECK_ROTATE_IDIOM return rot ? (value >> rot) | (value << (bits - rot)) : value; #else - return (value >> rot) | (value << ((- rot) & mask)); + return (value >> rot) | (value << ((-rot) & mask)); #endif } @@ -318,32 +297,28 @@ namespace pcg_extras { * * These overloads will be preferred over the general template code above. */ -#if PCG_USE_INLINE_ASM && __GNUC__ && (__x86_64__ || __i386__) +#if PCG_USE_INLINE_ASM && __GNUC__ && (__x86_64__ || __i386__) - inline uint8_t rotr(uint8_t value, bitcount_t rot) -{ - asm ("rorb %%cl, %0" : "=r" (value) : "0" (value), "c" (rot)); - return value; -} + inline uint8_t rotr(uint8_t value, bitcount_t rot) { + asm("rorb %%cl, %0" : "=r"(value) : "0"(value), "c"(rot)); + return value; + } -inline uint16_t rotr(uint16_t value, bitcount_t rot) -{ - asm ("rorw %%cl, %0" : "=r" (value) : "0" (value), "c" (rot)); - return value; -} + inline uint16_t rotr(uint16_t value, bitcount_t rot) { + asm("rorw %%cl, %0" : "=r"(value) : "0"(value), "c"(rot)); + return value; + } -inline uint32_t rotr(uint32_t value, bitcount_t rot) -{ - asm ("rorl %%cl, %0" : "=r" (value) : "0" (value), "c" (rot)); - return value; -} + inline uint32_t rotr(uint32_t value, bitcount_t rot) { + asm("rorl %%cl, %0" : "=r"(value) : "0"(value), "c"(rot)); + return value; + } #if __x86_64__ -inline uint64_t rotr(uint64_t value, bitcount_t rot) -{ - asm ("rorq %%cl, %0" : "=r" (value) : "0" (value), "c" (rot)); - return value; -} + inline uint64_t rotr(uint64_t value, bitcount_t rot) { + asm("rorq %%cl, %0" : "=r"(value) : "0"(value), "c"(rot)); + return value; + } #endif // __x86_64__ #elif defined(_MSC_VER) @@ -351,97 +326,78 @@ inline uint64_t rotr(uint64_t value, bitcount_t rot) #pragma intrinsic(_rotr, _rotr64, _rotr8, _rotr16) -inline uint8_t rotr(uint8_t value, bitcount_t rot) -{ - return _rotr8(value, rot); -} + inline uint8_t rotr(uint8_t value, bitcount_t rot) { return _rotr8(value, rot); } -inline uint16_t rotr(uint16_t value, bitcount_t rot) -{ - return _rotr16(value, rot); -} + inline uint16_t rotr(uint16_t value, bitcount_t rot) { return _rotr16(value, rot); } -inline uint32_t rotr(uint32_t value, bitcount_t rot) -{ - return _rotr(value, rot); -} + inline uint32_t rotr(uint32_t value, bitcount_t rot) { return _rotr(value, rot); } -inline uint64_t rotr(uint64_t value, bitcount_t rot) -{ - return _rotr64(value, rot); -} + inline uint64_t rotr(uint64_t value, bitcount_t rot) { return _rotr64(value, rot); } #endif // PCG_USE_INLINE_ASM - -/* - * The C++ SeedSeq concept (modelled by seed_seq) can fill an array of - * 32-bit integers with seed data, but sometimes we want to produce - * larger or smaller integers. - * - * The following code handles this annoyance. - * - * uneven_copy will copy an array of 32-bit ints to an array of larger or - * smaller ints (actually, the code is general it only needing forward - * iterators). The copy is identical to the one that would be performed if - * we just did memcpy on a standard little-endian machine, but works - * regardless of the endian of the machine (or the weirdness of the ints - * involved). - * - * generate_to initializes an array of integers using a SeedSeq - * object. It is given the size as a static constant at compile time and - * tries to avoid memory allocation. If we're filling in 32-bit constants - * we just do it directly. If we need a separate buffer and it's small, - * we allocate it on the stack. Otherwise, we fall back to heap allocation. - * Ugh. - * - * generate_one produces a single value of some integral type using a - * SeedSeq object. - */ + /* + * The C++ SeedSeq concept (modelled by seed_seq) can fill an array of + * 32-bit integers with seed data, but sometimes we want to produce + * larger or smaller integers. + * + * The following code handles this annoyance. + * + * uneven_copy will copy an array of 32-bit ints to an array of larger or + * smaller ints (actually, the code is general it only needing forward + * iterators). The copy is identical to the one that would be performed if + * we just did memcpy on a standard little-endian machine, but works + * regardless of the endian of the machine (or the weirdness of the ints + * involved). + * + * generate_to initializes an array of integers using a SeedSeq + * object. It is given the size as a static constant at compile time and + * tries to avoid memory allocation. If we're filling in 32-bit constants + * we just do it directly. If we need a separate buffer and it's small, + * we allocate it on the stack. Otherwise, we fall back to heap allocation. + * Ugh. + * + * generate_one produces a single value of some integral type using a + * SeedSeq object. + */ /* uneven_copy helper, case where destination ints are less than 32 bit. */ - template - SrcIter uneven_copy_impl( - SrcIter src_first, DestIter dest_first, DestIter dest_last, - std::true_type) - { - typedef typename std::iterator_traits::value_type src_t; + template + SrcIter uneven_copy_impl(SrcIter src_first, DestIter dest_first, DestIter dest_last, std::true_type) { + typedef typename std::iterator_traits::value_type src_t; typedef typename std::iterator_traits::value_type dest_t; - constexpr bitcount_t SRC_SIZE = sizeof(src_t); + constexpr bitcount_t SRC_SIZE = sizeof(src_t); constexpr bitcount_t DEST_SIZE = sizeof(dest_t); constexpr bitcount_t DEST_BITS = DEST_SIZE * 8; - constexpr bitcount_t SCALE = SRC_SIZE / DEST_SIZE; + constexpr bitcount_t SCALE = SRC_SIZE / DEST_SIZE; size_t count = 0; src_t value = 0; while (dest_first != dest_last) { if ((count++ % SCALE) == 0) - value = *src_first++; // Get more bits + value = *src_first++; // Get more bits else - value >>= DEST_BITS; // Move down bits + value >>= DEST_BITS; // Move down bits - *dest_first++ = dest_t(value); // Truncates, ignores high bits. + *dest_first++ = dest_t(value); // Truncates, ignores high bits. } return src_first; } /* uneven_copy helper, case where destination ints are more than 32 bit. */ - template - SrcIter uneven_copy_impl( - SrcIter src_first, DestIter dest_first, DestIter dest_last, - std::false_type) - { - typedef typename std::iterator_traits::value_type src_t; + template + SrcIter uneven_copy_impl(SrcIter src_first, DestIter dest_first, DestIter dest_last, std::false_type) { + typedef typename std::iterator_traits::value_type src_t; typedef typename std::iterator_traits::value_type dest_t; - constexpr auto SRC_SIZE = sizeof(src_t); - constexpr auto SRC_BITS = SRC_SIZE * 8; + constexpr auto SRC_SIZE = sizeof(src_t); + constexpr auto SRC_BITS = SRC_SIZE * 8; constexpr auto DEST_SIZE = sizeof(dest_t); - constexpr auto SCALE = (DEST_SIZE+SRC_SIZE-1) / SRC_SIZE; + constexpr auto SCALE = (DEST_SIZE + SRC_SIZE - 1) / SRC_SIZE; while (dest_first != dest_last) { dest_t value(0UL); @@ -457,91 +413,76 @@ inline uint64_t rotr(uint64_t value, bitcount_t rot) return src_first; } -/* uneven_copy, call the right code for larger vs. smaller */ + /* uneven_copy, call the right code for larger vs. smaller */ - template - inline SrcIter uneven_copy(SrcIter src_first, - DestIter dest_first, DestIter dest_last) - { - typedef typename std::iterator_traits::value_type src_t; + template + inline SrcIter uneven_copy(SrcIter src_first, DestIter dest_first, DestIter dest_last) { + typedef typename std::iterator_traits::value_type src_t; typedef typename std::iterator_traits::value_type dest_t; constexpr bool DEST_IS_SMALLER = sizeof(dest_t) < sizeof(src_t); - return uneven_copy_impl(src_first, dest_first, dest_last, - std::integral_constant{}); + return uneven_copy_impl(src_first, dest_first, dest_last, std::integral_constant{}); } -/* generate_to, fill in a fixed-size array of integral type using a SeedSeq - * (actually works for any random-access iterator) - */ + /* generate_to, fill in a fixed-size array of integral type using a SeedSeq + * (actually works for any random-access iterator) + */ template - inline void generate_to_impl(SeedSeq&& generator, DestIter dest, - std::true_type) - { - generator.generate(dest, dest+size); + inline void generate_to_impl(SeedSeq&& generator, DestIter dest, std::true_type) { + generator.generate(dest, dest + size); } template - void generate_to_impl(SeedSeq&& generator, DestIter dest, - std::false_type) - { + void generate_to_impl(SeedSeq&& generator, DestIter dest, std::false_type) { typedef typename std::iterator_traits::value_type dest_t; constexpr auto DEST_SIZE = sizeof(dest_t); - constexpr auto GEN_SIZE = sizeof(uint32_t); + constexpr auto GEN_SIZE = sizeof(uint32_t); constexpr bool GEN_IS_SMALLER = GEN_SIZE < DEST_SIZE; constexpr size_t FROM_ELEMS = - GEN_IS_SMALLER - ? size * ((DEST_SIZE+GEN_SIZE-1) / GEN_SIZE) - : (size + (GEN_SIZE / DEST_SIZE) - 1) - / ((GEN_SIZE / DEST_SIZE) + GEN_IS_SMALLER); + GEN_IS_SMALLER ? size * ((DEST_SIZE + GEN_SIZE - 1) / GEN_SIZE) + : (size + (GEN_SIZE / DEST_SIZE) - 1) / ((GEN_SIZE / DEST_SIZE) + GEN_IS_SMALLER); // this odd code ^^^^^^^^^^^^^^^^^ is work-around for // a bug: http://llvm.org/bugs/show_bug.cgi?id=21287 if (FROM_ELEMS <= 1024) { uint32_t buffer[FROM_ELEMS]; - generator.generate(buffer, buffer+FROM_ELEMS); - uneven_copy(buffer, dest, dest+size); + generator.generate(buffer, buffer + FROM_ELEMS); + uneven_copy(buffer, dest, dest + size); } else { uint32_t* buffer = static_cast(malloc(GEN_SIZE * FROM_ELEMS)); - generator.generate(buffer, buffer+FROM_ELEMS); - uneven_copy(buffer, dest, dest+size); + generator.generate(buffer, buffer + FROM_ELEMS); + uneven_copy(buffer, dest, dest + size); free(static_cast(buffer)); } } template - inline void generate_to(SeedSeq&& generator, DestIter dest) - { + inline void generate_to(SeedSeq&& generator, DestIter dest) { typedef typename std::iterator_traits::value_type dest_t; constexpr bool IS_32BIT = sizeof(dest_t) == sizeof(uint32_t); - generate_to_impl(std::forward(generator), dest, - std::integral_constant{}); + generate_to_impl(std::forward(generator), dest, std::integral_constant{}); } -/* generate_one, produce a value of integral type using a SeedSeq - * (optionally, we can have it produce more than one and pick which one - * we want) - */ + /* generate_one, produce a value of integral type using a SeedSeq + * (optionally, we can have it produce more than one and pick which one + * we want) + */ - template - inline UInt generate_one(SeedSeq&& generator) - { + template + inline UInt generate_one(SeedSeq&& generator) { UInt result[N]; generate_to(std::forward(generator), result); return result[i]; } template - auto bounded_rand(RngType& rng, typename RngType::result_type upper_bound) - -> typename RngType::result_type - { + auto bounded_rand(RngType& rng, typename RngType::result_type upper_bound) -> typename RngType::result_type { typedef typename RngType::result_type rtype; - rtype threshold = (RngType::max() - RngType::min() + rtype(1) - upper_bound) - % upper_bound; + rtype threshold = (RngType::max() - RngType::min() + rtype(1) - upper_bound) % upper_bound; for (;;) { rtype r = rng() - RngType::min(); if (r >= threshold) @@ -549,9 +490,7 @@ inline uint64_t rotr(uint64_t value, bitcount_t rot) } } - template - void shuffle(Iter from, Iter to, RandType&& rng) - { + template void shuffle(Iter from, Iter to, RandType&& rng) { typedef typename std::iterator_traits::difference_type delta_t; typedef typename std::remove_reference::type::result_type result_t; auto count = to - from; @@ -564,89 +503,74 @@ inline uint64_t rotr(uint64_t value, bitcount_t rot) } } -/* - * Although std::seed_seq is useful, it isn't everything. Often we want to - * initialize a random-number generator some other way, such as from a random - * device. - * - * Technically, it does not meet the requirements of a SeedSequence because - * it lacks some of the rarely-used member functions (some of which would - * be impossible to provide). However the C++ standard is quite specific - * that actual engines only called the generate method, so it ought not to be - * a problem in practice. - */ + /* + * Although std::seed_seq is useful, it isn't everything. Often we want to + * initialize a random-number generator some other way, such as from a random + * device. + * + * Technically, it does not meet the requirements of a SeedSequence because + * it lacks some of the rarely-used member functions (some of which would + * be impossible to provide). However the C++ standard is quite specific + * that actual engines only called the generate method, so it ought not to be + * a problem in practice. + */ - template - class seed_seq_from { + template class seed_seq_from { private: RngType rng_; typedef uint_least32_t result_type; public: - template - seed_seq_from(Args&&... args) : - rng_(std::forward(args)...) - { + template seed_seq_from(Args&&... args) : rng_(std::forward(args)...) { // Nothing (else) to do... } - template - void generate(Iter start, Iter finish) - { + template void generate(Iter start, Iter finish) { for (auto i = start; i != finish; ++i) *i = result_type(rng_()); } - constexpr size_t size() const - { - return (sizeof(typename RngType::result_type) > sizeof(result_type) - && RngType::max() > ~size_t(0UL)) - ? ~size_t(0UL) - : size_t(RngType::max()); + constexpr size_t size() const { + return (sizeof(typename RngType::result_type) > sizeof(result_type) && RngType::max() > ~size_t(0UL)) + ? ~size_t(0UL) + : size_t(RngType::max()); } }; -/* - * Sometimes you might want a distinct seed based on when the program - * was compiled. That way, a particular instance of the program will - * behave the same way, but when recompiled it'll produce a different - * value. - */ + /* + * Sometimes you might want a distinct seed based on when the program + * was compiled. That way, a particular instance of the program will + * behave the same way, but when recompiled it'll produce a different + * value. + */ - template - struct static_arbitrary_seed { + template struct static_arbitrary_seed { private: static constexpr IntType fnv(IntType hash, const char* pos) { - return *pos == '\0' - ? hash - : fnv((hash * IntType(16777619U)) ^ *pos, (pos+1)); + return *pos == '\0' ? hash : fnv((hash * IntType(16777619U)) ^ *pos, (pos + 1)); } public: - static constexpr IntType value = fnv(IntType(2166136261U ^ sizeof(IntType)), - __DATE__ __TIME__ __FILE__); + static constexpr IntType value = fnv(IntType(2166136261U ^ sizeof(IntType)), __DATE__ __TIME__ __FILE__); }; -// Sometimes, when debugging or testing, it's handy to be able print the name -// of a (in human-readable form). This code allows the idiom: -// -// cout << printable_typename() -// -// to print out my_foo_type_t (or its concrete type if it is a synonym) + // Sometimes, when debugging or testing, it's handy to be able print the name + // of a (in human-readable form). This code allows the idiom: + // + // cout << printable_typename() + // + // to print out my_foo_type_t (or its concrete type if it is a synonym) #if __cpp_rtti || __GXX_RTTI - template - struct printable_typename {}; + template struct printable_typename {}; - template - std::ostream& operator<<(std::ostream& out, printable_typename) { - const char *implementation_typename = typeid(T).name(); + template std::ostream& operator<<(std::ostream& out, printable_typename) { + const char* implementation_typename = typeid(T).name(); #ifdef __GNUC__ int status; - char* pretty_name = - abi::__cxa_demangle(implementation_typename, nullptr, nullptr, &status); + char* pretty_name = abi::__cxa_demangle(implementation_typename, nullptr, nullptr, &status); if (status == 0) out << pretty_name; free(static_cast(pretty_name)); @@ -657,7 +581,7 @@ inline uint64_t rotr(uint64_t value, bitcount_t rot) return out; } -#endif // __cpp_rtti || __GXX_RTTI +#endif // __cpp_rtti || __GXX_RTTI } // namespace pcg_extras diff --git a/extern/pcg_random.hpp b/extern/pcg_random.hpp index af7d179..92f6b46 100644 --- a/extern/pcg_random.hpp +++ b/extern/pcg_random.hpp @@ -74,22 +74,22 @@ #define PCG_RAND_HPP_INCLUDED 1 #include +#include #include #include #include #include -#include -#include #include #include -#include -#include +#include #include #include #include +#include +#include #ifdef _MSC_VER -#pragma warning(disable:4146) +#pragma warning(disable : 4146) #endif #ifdef _MSC_VER @@ -117,202 +117,155 @@ namespace pcg_detail { using namespace pcg_extras; -/* - * The LCG generators need some constants to function. This code lets you - * look up the constant by *type*. For example - * - * default_multiplier::multiplier() - * - * gives you the default multipler for 32-bit integers. We use the name - * of the constant and not a generic word like value to allow these classes - * to be used as mixins. - */ + /* + * The LCG generators need some constants to function. This code lets you + * look up the constant by *type*. For example + * + * default_multiplier::multiplier() + * + * gives you the default multipler for 32-bit integers. We use the name + * of the constant and not a generic word like value to allow these classes + * to be used as mixins. + */ - template - struct default_multiplier { + template struct default_multiplier { // Not defined for an arbitrary type }; - template - struct default_increment { + template struct default_increment { // Not defined for an arbitrary type }; -#define PCG_DEFINE_CONSTANT(type, what, kind, constant) \ - template <> \ - struct what ## _ ## kind { \ - static constexpr type kind() { \ - return constant; \ - } \ - }; +#define PCG_DEFINE_CONSTANT(type, what, kind, constant) \ + template <> struct what##_##kind { \ + static constexpr type kind() { return constant; } \ + }; - PCG_DEFINE_CONSTANT(uint8_t, default, multiplier, 141U) - PCG_DEFINE_CONSTANT(uint8_t, default, increment, 77U) + PCG_DEFINE_CONSTANT(uint8_t, default, multiplier, 141U) + PCG_DEFINE_CONSTANT(uint8_t, default, increment, 77U) PCG_DEFINE_CONSTANT(uint16_t, default, multiplier, 12829U) - PCG_DEFINE_CONSTANT(uint16_t, default, increment, 47989U) + PCG_DEFINE_CONSTANT(uint16_t, default, increment, 47989U) PCG_DEFINE_CONSTANT(uint32_t, default, multiplier, 747796405U) - PCG_DEFINE_CONSTANT(uint32_t, default, increment, 2891336453U) + PCG_DEFINE_CONSTANT(uint32_t, default, increment, 2891336453U) PCG_DEFINE_CONSTANT(uint64_t, default, multiplier, 6364136223846793005ULL) - PCG_DEFINE_CONSTANT(uint64_t, default, increment, 1442695040888963407ULL) + PCG_DEFINE_CONSTANT(uint64_t, default, increment, 1442695040888963407ULL) PCG_DEFINE_CONSTANT(pcg128_t, default, multiplier, - PCG_128BIT_CONSTANT(2549297995355413924ULL,4865540595714422341ULL)) + PCG_128BIT_CONSTANT(2549297995355413924ULL, 4865540595714422341ULL)) PCG_DEFINE_CONSTANT(pcg128_t, default, increment, - PCG_128BIT_CONSTANT(6364136223846793005ULL,1442695040888963407ULL)) + PCG_128BIT_CONSTANT(6364136223846793005ULL, 1442695040888963407ULL)) -/* Alternative (cheaper) multipliers for 128-bit */ + /* Alternative (cheaper) multipliers for 128-bit */ - template - struct cheap_multiplier : public default_multiplier { + template struct cheap_multiplier : public default_multiplier { // For most types just use the default. }; - template <> - struct cheap_multiplier { - static constexpr uint64_t multiplier() { - return 0xda942042e4dd58b5ULL; - } + template <> struct cheap_multiplier { + static constexpr uint64_t multiplier() { return 0xda942042e4dd58b5ULL; } }; + /* + * Each PCG generator is available in four variants, based on how it applies + * the additive constant for its underlying LCG; the variations are: + * + * single stream - all instances use the same fixed constant, thus + * the RNG always somewhere in same sequence + * mcg - adds zero, resulting in a single stream and reduced + * period + * specific stream - the constant can be changed at any time, selecting + * a different random sequence + * unique stream - the constant is based on the memory address of the + * object, thus every RNG has its own unique sequence + * + * This variation is provided though mixin classes which define a function + * value called increment() that returns the nesessary additive constant. + */ -/* - * Each PCG generator is available in four variants, based on how it applies - * the additive constant for its underlying LCG; the variations are: - * - * single stream - all instances use the same fixed constant, thus - * the RNG always somewhere in same sequence - * mcg - adds zero, resulting in a single stream and reduced - * period - * specific stream - the constant can be changed at any time, selecting - * a different random sequence - * unique stream - the constant is based on the memory address of the - * object, thus every RNG has its own unique sequence - * - * This variation is provided though mixin classes which define a function - * value called increment() that returns the nesessary additive constant. - */ + /* + * unique stream + */ - - -/* - * unique stream - */ - - - template - class unique_stream { + template class unique_stream { protected: static constexpr bool is_mcg = false; // Is never called, but is provided for symmetry with specific_stream - void set_stream(...) - { - abort(); - } + void set_stream(...) { abort(); } public: typedef itype state_type; - constexpr itype increment() const { - return itype(reinterpret_cast(this) | 1); - } + constexpr itype increment() const { return itype(reinterpret_cast(this) | 1); } - constexpr itype stream() const - { - return increment() >> 1; - } + constexpr itype stream() const { return increment() >> 1; } static constexpr bool can_specify_stream = false; - static constexpr size_t streams_pow2() - { - return (sizeof(itype) < sizeof(size_t) ? sizeof(itype) - : sizeof(size_t))*8 - 1u; + static constexpr size_t streams_pow2() { + return (sizeof(itype) < sizeof(size_t) ? sizeof(itype) : sizeof(size_t)) * 8 - 1u; } protected: constexpr unique_stream() = default; }; + /* + * no stream (mcg) + */ -/* - * no stream (mcg) - */ - - template - class no_stream { + template class no_stream { protected: static constexpr bool is_mcg = true; // Is never called, but is provided for symmetry with specific_stream - void set_stream(...) - { - abort(); - } + void set_stream(...) { abort(); } public: typedef itype state_type; - static constexpr itype increment() { - return 0; - } + static constexpr itype increment() { return 0; } static constexpr bool can_specify_stream = false; - static constexpr size_t streams_pow2() - { - return 0u; - } + static constexpr size_t streams_pow2() { return 0u; } protected: constexpr no_stream() = default; }; + /* + * single stream/sequence (oneseq) + */ -/* - * single stream/sequence (oneseq) - */ - - template - class oneseq_stream : public default_increment { + template class oneseq_stream : public default_increment { protected: static constexpr bool is_mcg = false; // Is never called, but is provided for symmetry with specific_stream - void set_stream(...) - { - abort(); - } + void set_stream(...) { abort(); } public: typedef itype state_type; - static constexpr itype stream() - { - return default_increment::increment() >> 1; - } + static constexpr itype stream() { return default_increment::increment() >> 1; } static constexpr bool can_specify_stream = false; - static constexpr size_t streams_pow2() - { - return 0u; - } + static constexpr size_t streams_pow2() { return 0u; } protected: constexpr oneseq_stream() = default; }; + /* + * specific stream + */ -/* - * specific stream - */ - - template - class specific_stream { + template class specific_stream { protected: static constexpr bool is_mcg = false; @@ -322,155 +275,103 @@ namespace pcg_detail { typedef itype state_type; typedef itype stream_state; - constexpr itype increment() const { - return inc_; - } + constexpr itype increment() const { return inc_; } - itype stream() - { - return inc_ >> 1; - } + itype stream() { return inc_ >> 1; } - void set_stream(itype specific_seq) - { - inc_ = (specific_seq << 1) | 1; - } + void set_stream(itype specific_seq) { inc_ = (specific_seq << 1) | 1; } static constexpr bool can_specify_stream = true; - static constexpr size_t streams_pow2() - { - return (sizeof(itype)*8) - 1u; - } + static constexpr size_t streams_pow2() { return (sizeof(itype) * 8) - 1u; } protected: specific_stream() = default; - specific_stream(itype specific_seq) - : inc_(itype(specific_seq << 1) | itype(1U)) - { + specific_stream(itype specific_seq) : inc_(itype(specific_seq << 1) | itype(1U)) { // Nothing (else) to do. } }; + /* + * This is where it all comes together. This function joins together three + * mixin classes which define + * - the LCG additive constant (the stream) + * - the LCG multiplier + * - the output function + * in addition, we specify the type of the LCG state, and the result type, + * and whether to use the pre-advance version of the state for the output + * (increasing instruction-level parallelism) or the post-advance version + * (reducing register pressure). + * + * Given the high level of parameterization, the code has to use some + * template-metaprogramming tricks to handle some of the suble variations + * involved. + */ -/* - * This is where it all comes together. This function joins together three - * mixin classes which define - * - the LCG additive constant (the stream) - * - the LCG multiplier - * - the output function - * in addition, we specify the type of the LCG state, and the result type, - * and whether to use the pre-advance version of the state for the output - * (increasing instruction-level parallelism) or the post-advance version - * (reducing register pressure). - * - * Given the high level of parameterization, the code has to use some - * template-metaprogramming tricks to handle some of the suble variations - * involved. - */ - - template , - typename multiplier_mixin = default_multiplier > - class engine : protected output_mixin, - public stream_mixin, - protected multiplier_mixin { + template , typename multiplier_mixin = default_multiplier> + class engine : protected output_mixin, public stream_mixin, protected multiplier_mixin { protected: itype state_; struct can_specify_stream_tag {}; struct no_specifiable_stream_tag {}; - using stream_mixin::increment; using multiplier_mixin::multiplier; + using stream_mixin::increment; public: typedef xtype result_type; typedef itype state_type; - static constexpr size_t period_pow2() - { - return sizeof(state_type)*8 - 2*stream_mixin::is_mcg; - } + static constexpr size_t period_pow2() { return sizeof(state_type) * 8 - 2 * stream_mixin::is_mcg; } // It would be nice to use std::numeric_limits for these, but // we can't be sure that it'd be defined for the 128-bit types. - static constexpr result_type min() - { - return result_type(0UL); - } + static constexpr result_type min() { return result_type(0UL); } - static constexpr result_type max() - { - return result_type(~result_type(0UL)); - } + static constexpr result_type max() { return result_type(~result_type(0UL)); } protected: - itype bump(itype state) - { - return state * multiplier() + increment(); - } + itype bump(itype state) { return state * multiplier() + increment(); } - itype base_generate() - { - return state_ = bump(state_); - } + itype base_generate() { return state_ = bump(state_); } - itype base_generate0() - { + itype base_generate0() { itype old_state = state_; state_ = bump(state_); return old_state; } public: - result_type operator()() - { + result_type operator()() { if (output_previous) return this->output(base_generate0()); else return this->output(base_generate()); } - result_type operator()(result_type upper_bound) - { - return bounded_rand(*this, upper_bound); - } + result_type operator()(result_type upper_bound) { return bounded_rand(*this, upper_bound); } protected: - static itype advance(itype state, itype delta, - itype cur_mult, itype cur_plus); + static itype advance(itype state, itype delta, itype cur_mult, itype cur_plus); - static itype distance(itype cur_state, itype newstate, itype cur_mult, - itype cur_plus, itype mask = ~itype(0U)); + static itype distance(itype cur_state, itype newstate, itype cur_mult, itype cur_plus, itype mask = ~itype(0U)); - itype distance(itype newstate, itype mask = itype(~itype(0U))) const - { + itype distance(itype newstate, itype mask = itype(~itype(0U))) const { return distance(state_, newstate, multiplier(), increment(), mask); } public: - void advance(itype delta) - { - state_ = advance(state_, delta, this->multiplier(), this->increment()); - } + void advance(itype delta) { state_ = advance(state_, delta, this->multiplier(), this->increment()); } - void backstep(itype delta) - { - advance(-delta); - } + void backstep(itype delta) { advance(-delta); } - void discard(itype delta) - { - advance(delta); - } + void discard(itype delta) { advance(delta); } - bool wrapped() - { + bool wrapped() { if (stream_mixin::is_mcg) { // For MCGs, the low order two bits never change. In this // implementation, we keep them fixed at 3 to make this test @@ -482,9 +383,7 @@ namespace pcg_detail { } engine(itype state = itype(0xcafef00dd15ea5e5ULL)) - : state_(this->is_mcg ? state|state_type(3U) - : bump(state + this->increment())) - { + : state_(this->is_mcg ? state | state_type(3U) : bump(state + this->increment())) { // Nothing else to do. } @@ -494,121 +393,82 @@ namespace pcg_detail { template engine(itype state, typename sm::stream_state stream_seed) : stream_mixin(stream_seed), - state_(this->is_mcg ? state|state_type(3U) - : bump(state + this->increment())) - { + state_(this->is_mcg ? state | state_type(3U) : bump(state + this->increment())) { // Nothing else to do. } - template - engine(SeedSeq&& seedSeq, typename std::enable_if< - !stream_mixin::can_specify_stream - && !std::is_convertible::value - && !std::is_convertible::value, - no_specifiable_stream_tag>::type = {}) - : engine(generate_one(std::forward(seedSeq))) - { + template + engine( + SeedSeq&& seedSeq, + typename std::enable_if::value && + !std::is_convertible::value, + no_specifiable_stream_tag>::type = {}) + : engine(generate_one(std::forward(seedSeq))) { // Nothing else to do. } - template - engine(SeedSeq&& seedSeq, typename std::enable_if< - stream_mixin::can_specify_stream - && !std::is_convertible::value - && !std::is_convertible::value, - can_specify_stream_tag>::type = {}) - : engine(generate_one(seedSeq), - generate_one(seedSeq)) - { + template + engine( + SeedSeq&& seedSeq, + typename std::enable_if::value && + !std::is_convertible::value, + can_specify_stream_tag>::type = {}) + : engine(generate_one(seedSeq), generate_one(seedSeq)) { // Nothing else to do. } + template void seed(Args&&... args) { new (this) engine(std::forward(args)...); } - template - void seed(Args&&... args) - { - new (this) engine(std::forward(args)...); - } + template + friend bool operator==( + const engine&, + const engine&); - template - friend bool operator==(const engine&, - const engine&); + template + friend itype1 operator-( + const engine&, + const engine&); - template - friend itype1 operator-(const engine&, - const engine&); + template + friend std::basic_ostream& + operator<<(std::basic_ostream& out, + const engine&); - template - friend std::basic_ostream& - operator<<(std::basic_ostream& out, - const engine&); - - template - friend std::basic_istream& - operator>>(std::basic_istream& in, - engine& rng); + template + friend std::basic_istream& + operator>>(std::basic_istream& in, + engine& rng); }; - template - std::basic_ostream& - operator<<(std::basic_ostream& out, - const engine& rng) - { + template + std::basic_ostream& + operator<<(std::basic_ostream& out, + const engine& rng) { using pcg_extras::operator<<; auto orig_flags = out.flags(std::ios_base::dec | std::ios_base::left); auto space = out.widen(' '); auto orig_fill = out.fill(); - out << rng.multiplier() << space - << rng.increment() << space - << rng.state_; + out << rng.multiplier() << space << rng.increment() << space << rng.state_; out.flags(orig_flags); out.fill(orig_fill); return out; } - - template - std::basic_istream& - operator>>(std::basic_istream& in, - engine& rng) - { + template + std::basic_istream& + operator>>(std::basic_istream& in, + engine& rng) { using pcg_extras::operator>>; auto orig_flags = in.flags(std::ios_base::dec | std::ios_base::skipws); @@ -636,14 +496,12 @@ namespace pcg_detail { return in; } - - template - itype engine::advance( - itype state, itype delta, itype cur_mult, itype cur_plus) - { + template + itype engine::advance(itype state, + itype delta, + itype cur_mult, + itype cur_plus) { // The method used here is based on Brown, "Random Number Generation // with Arbitrary Stride,", Transactions of the American Nuclear // Society (Nov. 1994). The algorithm is very similar to fast @@ -652,30 +510,27 @@ namespace pcg_detail { // Even though delta is an unsigned integer, we can pass a // signed integer to go backwards, it just goes "the long way round". - constexpr itype ZERO = 0u; // itype may be a non-trivial types, so - constexpr itype ONE = 1u; // we define some ugly constants. + constexpr itype ZERO = 0u; // itype may be a non-trivial types, so + constexpr itype ONE = 1u; // we define some ugly constants. itype acc_mult = 1; itype acc_plus = 0; while (delta > ZERO) { if (delta & ONE) { acc_mult *= cur_mult; - acc_plus = acc_plus*cur_mult + cur_plus; + acc_plus = acc_plus * cur_mult + cur_plus; } - cur_plus = (cur_mult+ONE)*cur_plus; + cur_plus = (cur_mult + ONE) * cur_plus; cur_mult *= cur_mult; delta >>= 1; } return acc_mult * state + acc_plus; } - template - itype engine::distance( - itype cur_state, itype newstate, itype cur_mult, itype cur_plus, itype mask) - { - constexpr itype ONE = 1u; // itype could be weird, so use constant + template + itype engine::distance( + itype cur_state, itype newstate, itype cur_mult, itype cur_plus, itype mask) { + constexpr itype ONE = 1u; // itype could be weird, so use constant bool is_mcg = cur_plus == itype(0); itype the_bit = is_mcg ? itype(4u) : itype(1u); itype distance = 0u; @@ -686,33 +541,26 @@ namespace pcg_detail { } assert((cur_state & the_bit) == (newstate & the_bit)); the_bit <<= 1; - cur_plus = (cur_mult+ONE)*cur_plus; + cur_plus = (cur_mult + ONE) * cur_plus; cur_mult *= cur_mult; } return is_mcg ? distance >> 2 : distance; } - template - itype operator-(const engine& lhs, - const engine& rhs) - { - static_assert( - std::is_same::value && - std::is_same::value, - "Incomparable generators"); + template + itype + operator-(const engine& lhs, + const engine& rhs) { + static_assert(std::is_same::value && + std::is_same::value, + "Incomparable generators"); if (lhs.increment() == rhs.increment()) { return rhs.distance(lhs.state_); - } else { + } else { constexpr itype ONE = 1u; - itype lhs_diff = lhs.increment() + (lhs.multiplier()-ONE) * lhs.state_; - itype rhs_diff = rhs.increment() + (rhs.multiplier()-ONE) * rhs.state_; + itype lhs_diff = lhs.increment() + (lhs.multiplier() - ONE) * lhs.state_; + itype rhs_diff = rhs.increment() + (rhs.multiplier() - ONE) * rhs.state_; if ((lhs_diff & itype(3u)) != (rhs_diff & itype(3u))) { rhs_diff = -rhs_diff; } @@ -720,150 +568,110 @@ namespace pcg_detail { } } - - template - bool operator==(const engine& lhs, - const engine& rhs) - { - return (lhs.multiplier() == rhs.multiplier()) - && (lhs.increment() == rhs.increment()) - && (lhs.state_ == rhs.state_); + template + bool + operator==(const engine& lhs, + const engine& rhs) { + return (lhs.multiplier() == rhs.multiplier()) && (lhs.increment() == rhs.increment()) && + (lhs.state_ == rhs.state_); } - template - inline bool operator!=(const engine& lhs, - const engine& rhs) - { - return !operator==(lhs,rhs); + template + inline bool + operator!=(const engine& lhs, + const engine& rhs) { + return !operator==(lhs, rhs); } + template class output_mixin, + bool output_previous = (sizeof(itype) <= 8), + template class multiplier_mixin = default_multiplier> + using oneseq_base = engine, output_previous, oneseq_stream, + multiplier_mixin>; - template class output_mixin, - bool output_previous = (sizeof(itype) <= 8), - template class multiplier_mixin = default_multiplier> - using oneseq_base = engine, output_previous, - oneseq_stream, - multiplier_mixin >; + template class output_mixin, + bool output_previous = (sizeof(itype) <= 8), + template class multiplier_mixin = default_multiplier> + using unique_base = engine, output_previous, unique_stream, + multiplier_mixin>; - template class output_mixin, - bool output_previous = (sizeof(itype) <= 8), - template class multiplier_mixin = default_multiplier> - using unique_base = engine, output_previous, - unique_stream, - multiplier_mixin >; + template class output_mixin, + bool output_previous = (sizeof(itype) <= 8), + template class multiplier_mixin = default_multiplier> + using setseq_base = engine, output_previous, specific_stream, + multiplier_mixin>; - template class output_mixin, - bool output_previous = (sizeof(itype) <= 8), - template class multiplier_mixin = default_multiplier> - using setseq_base = engine, output_previous, - specific_stream, - multiplier_mixin >; + template class output_mixin, + bool output_previous = (sizeof(itype) <= 8), + template class multiplier_mixin = default_multiplier> + using mcg_base = + engine, output_previous, no_stream, multiplier_mixin>; - template class output_mixin, - bool output_previous = (sizeof(itype) <= 8), - template class multiplier_mixin = default_multiplier> - using mcg_base = engine, output_previous, - no_stream, - multiplier_mixin >; + /* + * OUTPUT FUNCTIONS. + * + * These are the core of the PCG generation scheme. They specify how to + * turn the base LCG's internal state into the output value of the final + * generator. + * + * They're implemented as mixin classes. + * + * All of the classes have code that is written to allow it to be applied + * at *arbitrary* bit sizes, although in practice they'll only be used at + * standard sizes supported by C++. + */ -/* - * OUTPUT FUNCTIONS. - * - * These are the core of the PCG generation scheme. They specify how to - * turn the base LCG's internal state into the output value of the final - * generator. - * - * They're implemented as mixin classes. - * - * All of the classes have code that is written to allow it to be applied - * at *arbitrary* bit sizes, although in practice they'll only be used at - * standard sizes supported by C++. - */ + /* + * XSH RS -- high xorshift, followed by a random shift + * + * Fast. A good performer. + */ -/* - * XSH RS -- high xorshift, followed by a random shift - * - * Fast. A good performer. - */ - - template - struct xsh_rs_mixin { - static xtype output(itype internal) - { - constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); - constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); - constexpr bitcount_t sparebits = bits - xtypebits; + template struct xsh_rs_mixin { + static xtype output(itype internal) { + constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); + constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); + constexpr bitcount_t sparebits = bits - xtypebits; constexpr bitcount_t opbits = - sparebits-5 >= 64 ? 5 - : sparebits-4 >= 32 ? 4 - : sparebits-3 >= 16 ? 3 - : sparebits-2 >= 4 ? 2 - : sparebits-1 >= 1 ? 1 - : 0; + sparebits - 5 >= 64 + ? 5 + : sparebits - 4 >= 32 + ? 4 + : sparebits - 3 >= 16 ? 3 : sparebits - 2 >= 4 ? 2 : sparebits - 1 >= 1 ? 1 : 0; constexpr bitcount_t mask = (1 << opbits) - 1; - constexpr bitcount_t maxrandshift = mask; - constexpr bitcount_t topspare = opbits; + constexpr bitcount_t maxrandshift = mask; + constexpr bitcount_t topspare = opbits; constexpr bitcount_t bottomspare = sparebits - topspare; - constexpr bitcount_t xshift = topspare + (xtypebits+maxrandshift)/2; - bitcount_t rshift = - opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; + constexpr bitcount_t xshift = topspare + (xtypebits + maxrandshift) / 2; + bitcount_t rshift = opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; internal ^= internal >> xshift; xtype result = xtype(internal >> (bottomspare - maxrandshift + rshift)); return result; } }; -/* - * XSH RR -- high xorshift, followed by a random rotate - * - * Fast. A good performer. Slightly better statistically than XSH RS. - */ + /* + * XSH RR -- high xorshift, followed by a random rotate + * + * Fast. A good performer. Slightly better statistically than XSH RS. + */ - template - struct xsh_rr_mixin { - static xtype output(itype internal) - { - constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); - constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype)*8); - constexpr bitcount_t sparebits = bits - xtypebits; + template struct xsh_rr_mixin { + static xtype output(itype internal) { + constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); + constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); + constexpr bitcount_t sparebits = bits - xtypebits; constexpr bitcount_t wantedopbits = - xtypebits >= 128 ? 7 - : xtypebits >= 64 ? 6 - : xtypebits >= 32 ? 5 - : xtypebits >= 16 ? 4 - : 3; - constexpr bitcount_t opbits = - sparebits >= wantedopbits ? wantedopbits - : sparebits; + xtypebits >= 128 ? 7 : xtypebits >= 64 ? 6 : xtypebits >= 32 ? 5 : xtypebits >= 16 ? 4 : 3; + constexpr bitcount_t opbits = sparebits >= wantedopbits ? wantedopbits : sparebits; constexpr bitcount_t amplifier = wantedopbits - opbits; constexpr bitcount_t mask = (1 << opbits) - 1; - constexpr bitcount_t topspare = opbits; + constexpr bitcount_t topspare = opbits; constexpr bitcount_t bottomspare = sparebits - topspare; - constexpr bitcount_t xshift = (topspare + xtypebits)/2; - bitcount_t rot = opbits ? bitcount_t(internal >> (bits - opbits)) & mask - : 0; + constexpr bitcount_t xshift = (topspare + xtypebits) / 2; + bitcount_t rot = opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; bitcount_t amprot = (rot << amplifier) & mask; internal ^= internal >> xshift; xtype result = xtype(internal >> bottomspare); @@ -872,68 +680,67 @@ namespace pcg_detail { } }; -/* - * RXS -- random xorshift - */ + /* + * RXS -- random xorshift + */ - template - struct rxs_mixin { - static xtype output_rxs(itype internal) - { - constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); - constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype)*8); - constexpr bitcount_t shift = bits - xtypebits; - constexpr bitcount_t extrashift = (xtypebits - shift)/2; - bitcount_t rshift = shift > 64+8 ? (internal >> (bits - 6)) & 63 - : shift > 32+4 ? (internal >> (bits - 5)) & 31 - : shift > 16+2 ? (internal >> (bits - 4)) & 15 - : shift > 8+1 ? (internal >> (bits - 3)) & 7 - : shift > 4+1 ? (internal >> (bits - 2)) & 3 - : shift > 2+1 ? (internal >> (bits - 1)) & 1 - : 0; + template struct rxs_mixin { + static xtype output_rxs(itype internal) { + constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); + constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); + constexpr bitcount_t shift = bits - xtypebits; + constexpr bitcount_t extrashift = (xtypebits - shift) / 2; + bitcount_t rshift = + shift > 64 + 8 + ? (internal >> (bits - 6)) & 63 + : shift > 32 + 4 + ? (internal >> (bits - 5)) & 31 + : shift > 16 + 2 + ? (internal >> (bits - 4)) & 15 + : shift > 8 + 1 ? (internal >> (bits - 3)) & 7 + : shift > 4 + 1 ? (internal >> (bits - 2)) & 3 + : shift > 2 + 1 ? (internal >> (bits - 1)) & 1 : 0; internal ^= internal >> (shift + extrashift - rshift); xtype result = internal >> rshift; return result; } }; -/* - * RXS M XS -- random xorshift, mcg multiply, fixed xorshift - * - * The most statistically powerful generator, but all those steps - * make it slower than some of the others. We give it the rottenest jobs. - * - * Because it's usually used in contexts where the state type and the - * result type are the same, it is a permutation and is thus invertable. - * We thus provide a function to invert it. This function is used to - * for the "inside out" generator used by the extended generator. - */ + /* + * RXS M XS -- random xorshift, mcg multiply, fixed xorshift + * + * The most statistically powerful generator, but all those steps + * make it slower than some of the others. We give it the rottenest jobs. + * + * Because it's usually used in contexts where the state type and the + * result type are the same, it is a permutation and is thus invertable. + * We thus provide a function to invert it. This function is used to + * for the "inside out" generator used by the extended generator. + */ -/* Defined type-based concepts for the multiplication step. They're actually - * all derived by truncating the 128-bit, which was computed to be a good - * "universal" constant. - */ + /* Defined type-based concepts for the multiplication step. They're actually + * all derived by truncating the 128-bit, which was computed to be a good + * "universal" constant. + */ - template - struct mcg_multiplier { + template struct mcg_multiplier { // Not defined for an arbitrary type }; - template - struct mcg_unmultiplier { + template struct mcg_unmultiplier { // Not defined for an arbitrary type }; - PCG_DEFINE_CONSTANT(uint8_t, mcg, multiplier, 217U) - PCG_DEFINE_CONSTANT(uint8_t, mcg, unmultiplier, 105U) + PCG_DEFINE_CONSTANT(uint8_t, mcg, multiplier, 217U) + PCG_DEFINE_CONSTANT(uint8_t, mcg, unmultiplier, 105U) - PCG_DEFINE_CONSTANT(uint16_t, mcg, multiplier, 62169U) + PCG_DEFINE_CONSTANT(uint16_t, mcg, multiplier, 62169U) PCG_DEFINE_CONSTANT(uint16_t, mcg, unmultiplier, 28009U) - PCG_DEFINE_CONSTANT(uint32_t, mcg, multiplier, 277803737U) + PCG_DEFINE_CONSTANT(uint32_t, mcg, multiplier, 277803737U) PCG_DEFINE_CONSTANT(uint32_t, mcg, unmultiplier, 2897767785U) - PCG_DEFINE_CONSTANT(uint64_t, mcg, multiplier, 12605985483714917081ULL) + PCG_DEFINE_CONSTANT(uint64_t, mcg, multiplier, 12605985483714917081ULL) PCG_DEFINE_CONSTANT(uint64_t, mcg, unmultiplier, 15009553638781119849ULL) PCG_DEFINE_CONSTANT(pcg128_t, mcg, multiplier, @@ -941,40 +748,28 @@ namespace pcg_detail { PCG_DEFINE_CONSTANT(pcg128_t, mcg, unmultiplier, PCG_128BIT_CONSTANT(14422606686972528997ULL, 15009553638781119849ULL)) - - template - struct rxs_m_xs_mixin { - static xtype output(itype internal) - { + template struct rxs_m_xs_mixin { + static xtype output(itype internal) { constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); - constexpr bitcount_t opbits = xtypebits >= 128 ? 6 - : xtypebits >= 64 ? 5 - : xtypebits >= 32 ? 4 - : xtypebits >= 16 ? 3 - : 2; + constexpr bitcount_t opbits = + xtypebits >= 128 ? 6 : xtypebits >= 64 ? 5 : xtypebits >= 32 ? 4 : xtypebits >= 16 ? 3 : 2; constexpr bitcount_t shift = bits - xtypebits; constexpr bitcount_t mask = (1 << opbits) - 1; - bitcount_t rshift = - opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; + bitcount_t rshift = opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; internal ^= internal >> (opbits + rshift); internal *= mcg_multiplier::multiplier(); xtype result = internal >> shift; - result ^= result >> ((2U*xtypebits+2U)/3U); + result ^= result >> ((2U * xtypebits + 2U) / 3U); return result; } - static itype unoutput(itype internal) - { + static itype unoutput(itype internal) { constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); - constexpr bitcount_t opbits = bits >= 128 ? 6 - : bits >= 64 ? 5 - : bits >= 32 ? 4 - : bits >= 16 ? 3 - : 2; + constexpr bitcount_t opbits = bits >= 128 ? 6 : bits >= 64 ? 5 : bits >= 32 ? 4 : bits >= 16 ? 3 : 2; constexpr bitcount_t mask = (1 << opbits) - 1; - internal = unxorshift(internal, bits, (2U*bits+2U)/3U); + internal = unxorshift(internal, bits, (2U * bits + 2U) / 3U); internal *= mcg_unmultiplier::unmultiplier(); @@ -985,22 +780,16 @@ namespace pcg_detail { } }; + /* + * RXS M -- random xorshift, mcg multiply + */ -/* - * RXS M -- random xorshift, mcg multiply - */ - - template - struct rxs_m_mixin { - static xtype output(itype internal) - { + template struct rxs_m_mixin { + static xtype output(itype internal) { constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); - constexpr bitcount_t opbits = xtypebits >= 128 ? 6 - : xtypebits >= 64 ? 5 - : xtypebits >= 32 ? 4 - : xtypebits >= 16 ? 3 - : 2; + constexpr bitcount_t opbits = + xtypebits >= 128 ? 6 : xtypebits >= 64 ? 5 : xtypebits >= 32 ? 4 : xtypebits >= 16 ? 3 : 2; constexpr bitcount_t shift = bits - xtypebits; constexpr bitcount_t mask = (1 << opbits) - 1; bitcount_t rshift = opbits ? (internal >> (bits - opbits)) & mask : 0; @@ -1011,73 +800,61 @@ namespace pcg_detail { } }; + /* + * DXSM -- double xorshift multiply + * + * This is a new, more powerful output permutation (added in 2019). It's + * a more comprehensive scrambling than RXS M, but runs faster on 128-bit + * types. Although primarily intended for use at large sizes, also works + * at smaller sizes as well. + * + * This permutation is similar to xorshift multiply hash functions, except + * that one of the multipliers is the LCG multiplier (to avoid needing to + * have a second constant) and the other is based on the low-order bits. + * This latter aspect means that the scrambling applied to the high bits + * depends on the low bits, and makes it (to my eye) impractical to back + * out the permutation without having the low-order bits. + */ -/* - * DXSM -- double xorshift multiply - * - * This is a new, more powerful output permutation (added in 2019). It's - * a more comprehensive scrambling than RXS M, but runs faster on 128-bit - * types. Although primarily intended for use at large sizes, also works - * at smaller sizes as well. - * - * This permutation is similar to xorshift multiply hash functions, except - * that one of the multipliers is the LCG multiplier (to avoid needing to - * have a second constant) and the other is based on the low-order bits. - * This latter aspect means that the scrambling applied to the high bits - * depends on the low bits, and makes it (to my eye) impractical to back - * out the permutation without having the low-order bits. - */ - - template - struct dxsm_mixin { - inline xtype output(itype internal) - { + template struct dxsm_mixin { + inline xtype output(itype internal) { constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); constexpr bitcount_t itypebits = bitcount_t(sizeof(itype) * 8); - static_assert(xtypebits <= itypebits/2, - "Output type must be half the size of the state type."); + static_assert(xtypebits <= itypebits / 2, "Output type must be half the size of the state type."); xtype hi = xtype(internal >> (itypebits - xtypebits)); xtype lo = xtype(internal); lo |= 1; - hi ^= hi >> (xtypebits/2); + hi ^= hi >> (xtypebits / 2); hi *= xtype(cheap_multiplier::multiplier()); - hi ^= hi >> (3*(xtypebits/4)); + hi ^= hi >> (3 * (xtypebits / 4)); hi *= lo; return hi; } }; + /* + * XSL RR -- fixed xorshift (to low bits), random rotate + * + * Useful for 128-bit types that are split across two CPU registers. + */ -/* - * XSL RR -- fixed xorshift (to low bits), random rotate - * - * Useful for 128-bit types that are split across two CPU registers. - */ - - template - struct xsl_rr_mixin { - static xtype output(itype internal) - { + template struct xsl_rr_mixin { + static xtype output(itype internal) { constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); constexpr bitcount_t sparebits = bits - xtypebits; - constexpr bitcount_t wantedopbits = xtypebits >= 128 ? 7 - : xtypebits >= 64 ? 6 - : xtypebits >= 32 ? 5 - : xtypebits >= 16 ? 4 - : 3; - constexpr bitcount_t opbits = sparebits >= wantedopbits ? wantedopbits - : sparebits; + constexpr bitcount_t wantedopbits = + xtypebits >= 128 ? 7 : xtypebits >= 64 ? 6 : xtypebits >= 32 ? 5 : xtypebits >= 16 ? 4 : 3; + constexpr bitcount_t opbits = sparebits >= wantedopbits ? wantedopbits : sparebits; constexpr bitcount_t amplifier = wantedopbits - opbits; constexpr bitcount_t mask = (1 << opbits) - 1; constexpr bitcount_t topspare = sparebits; constexpr bitcount_t bottomspare = sparebits - topspare; constexpr bitcount_t xshift = (topspare + xtypebits) / 2; - bitcount_t rot = - opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; + bitcount_t rot = opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; bitcount_t amprot = (rot << amplifier) & mask; internal ^= internal >> xshift; xtype result = xtype(internal >> bottomspare); @@ -1086,43 +863,35 @@ namespace pcg_detail { } }; - -/* - * XSL RR RR -- fixed xorshift (to low bits), random rotate (both parts) - * - * Useful for 128-bit types that are split across two CPU registers. - * If you really want an invertable 128-bit RNG, I guess this is the one. - */ + /* + * XSL RR RR -- fixed xorshift (to low bits), random rotate (both parts) + * + * Useful for 128-bit types that are split across two CPU registers. + * If you really want an invertable 128-bit RNG, I guess this is the one. + */ template struct halfsize_trait {}; - template <> struct halfsize_trait { typedef uint64_t type; }; - template <> struct halfsize_trait { typedef uint32_t type; }; - template <> struct halfsize_trait { typedef uint16_t type; }; - template <> struct halfsize_trait { typedef uint8_t type; }; + template <> struct halfsize_trait { typedef uint64_t type; }; + template <> struct halfsize_trait { typedef uint32_t type; }; + template <> struct halfsize_trait { typedef uint16_t type; }; + template <> struct halfsize_trait { typedef uint8_t type; }; - template - struct xsl_rr_rr_mixin { + template struct xsl_rr_rr_mixin { typedef typename halfsize_trait::type htype; - static itype output(itype internal) - { + static itype output(itype internal) { constexpr bitcount_t htypebits = bitcount_t(sizeof(htype) * 8); - constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); + constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); constexpr bitcount_t sparebits = bits - htypebits; - constexpr bitcount_t wantedopbits = htypebits >= 128 ? 7 - : htypebits >= 64 ? 6 - : htypebits >= 32 ? 5 - : htypebits >= 16 ? 4 - : 3; - constexpr bitcount_t opbits = sparebits >= wantedopbits ? wantedopbits - : sparebits; + constexpr bitcount_t wantedopbits = + htypebits >= 128 ? 7 : htypebits >= 64 ? 6 : htypebits >= 32 ? 5 : htypebits >= 16 ? 4 : 3; + constexpr bitcount_t opbits = sparebits >= wantedopbits ? wantedopbits : sparebits; constexpr bitcount_t amplifier = wantedopbits - opbits; constexpr bitcount_t mask = (1 << opbits) - 1; constexpr bitcount_t topspare = sparebits; constexpr bitcount_t xshift = (topspare + htypebits) / 2; - bitcount_t rot = - opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; + bitcount_t rot = opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0; bitcount_t amprot = (rot << amplifier) & mask; internal ^= internal >> xshift; htype lowbits = htype(internal); @@ -1135,17 +904,14 @@ namespace pcg_detail { } }; + /* + * XSH -- fixed xorshift (to high bits) + * + * You shouldn't use this at 64-bits or less. + */ -/* - * XSH -- fixed xorshift (to high bits) - * - * You shouldn't use this at 64-bits or less. - */ - - template - struct xsh_mixin { - static xtype output(itype internal) - { + template struct xsh_mixin { + static xtype output(itype internal) { constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); constexpr bitcount_t sparebits = bits - xtypebits; @@ -1159,16 +925,14 @@ namespace pcg_detail { } }; -/* - * XSL -- fixed xorshift (to low bits) - * - * You shouldn't use this at 64-bits or less. - */ + /* + * XSL -- fixed xorshift (to low bits) + * + * You shouldn't use this at 64-bits or less. + */ - template - struct xsl_mixin { - inline xtype output(itype internal) - { + template struct xsl_mixin { + inline xtype output(itype internal) { constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8); constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8); constexpr bitcount_t sparebits = bits - xtypebits; @@ -1182,43 +946,32 @@ namespace pcg_detail { } }; + /* ---- End of Output Functions ---- */ -/* ---- End of Output Functions ---- */ - - - template - struct inside_out : private baseclass { + template struct inside_out : private baseclass { inside_out() = delete; typedef typename baseclass::result_type result_type; - typedef typename baseclass::state_type state_type; + typedef typename baseclass::state_type state_type; static_assert(sizeof(result_type) == sizeof(state_type), "Require a RNG whose output function is a permutation"); - static bool external_step(result_type& randval, size_t i) - { + static bool external_step(result_type& randval, size_t i) { state_type state = baseclass::unoutput(randval); - state = state * baseclass::multiplier() + baseclass::increment() - + state_type(i*2); + state = state * baseclass::multiplier() + baseclass::increment() + state_type(i * 2); result_type result = baseclass::output(state); randval = result; - state_type zero = - baseclass::is_mcg ? state & state_type(3U) : state_type(0U); + state_type zero = baseclass::is_mcg ? state & state_type(3U) : state_type(0U); return result == zero; } - static bool external_advance(result_type& randval, size_t i, - result_type delta, bool forwards = true) - { + static bool external_advance(result_type& randval, size_t i, result_type delta, bool forwards = true) { state_type state = baseclass::unoutput(randval); - state_type mult = baseclass::multiplier(); - state_type inc = baseclass::increment() + state_type(i*2); - state_type zero = - baseclass::is_mcg ? state & state_type(3U) : state_type(0U); + state_type mult = baseclass::multiplier(); + state_type inc = baseclass::increment() + state_type(i * 2); + state_type zero = baseclass::is_mcg ? state & state_type(3U) : state_type(0U); state_type dist_to_zero = baseclass::distance(state, zero, mult, inc); - bool crosses_zero = - forwards ? dist_to_zero <= delta - : (-dist_to_zero) <= delta; + bool crosses_zero = forwards ? dist_to_zero <= delta : (-dist_to_zero) <= delta; if (!forwards) delta = -delta; state = baseclass::advance(state, delta, mult, inc); @@ -1227,33 +980,28 @@ namespace pcg_detail { } }; - template class extended : public baseclass { public: - typedef typename baseclass::state_type state_type; + typedef typename baseclass::state_type state_type; typedef typename baseclass::result_type result_type; typedef inside_out insideout; private: - static constexpr bitcount_t rtypebits = sizeof(result_type)*8; - static constexpr bitcount_t stypebits = sizeof(state_type)*8; + static constexpr bitcount_t rtypebits = sizeof(result_type) * 8; + static constexpr bitcount_t stypebits = sizeof(state_type) * 8; static constexpr bitcount_t tick_limit_pow2 = 64U; - static constexpr size_t table_size = 1UL << table_pow2; + static constexpr size_t table_size = 1UL << table_pow2; static constexpr size_t table_shift = stypebits - table_pow2; - static constexpr state_type table_mask = - (state_type(1U) << table_pow2) - state_type(1U); + static constexpr state_type table_mask = (state_type(1U) << table_pow2) - state_type(1U); - static constexpr bool may_tick = - (advance_pow2 < stypebits) && (advance_pow2 < tick_limit_pow2); + static constexpr bool may_tick = (advance_pow2 < stypebits) && (advance_pow2 < tick_limit_pow2); static constexpr size_t tick_shift = stypebits - advance_pow2; - static constexpr state_type tick_mask = - may_tick ? state_type( - (uint64_t(1) << (advance_pow2*may_tick)) - 1) - // ^-- stupidity to appease GCC warnings - : ~state_type(0U); + static constexpr state_type tick_mask = may_tick ? state_type((uint64_t(1) << (advance_pow2 * may_tick)) - 1) + // ^-- stupidity to appease GCC warnings + : ~state_type(0U); static constexpr bool may_tock = stypebits < tick_limit_pow2; @@ -1263,19 +1011,16 @@ namespace pcg_detail { PCG_NOINLINE void advance_table(state_type delta, bool isForwards = true); - result_type& get_extended_value() - { + result_type& get_extended_value() { state_type state = this->state_; if (kdd && baseclass::is_mcg) { // The low order bits of an MCG are constant, so drop them. state >>= 2; } - size_t index = kdd ? state & table_mask - : state >> table_shift; + size_t index = kdd ? state & table_mask : state >> table_shift; if (may_tick) { - bool tick = kdd ? (state & tick_mask) == state_type(0u) - : (state >> tick_shift) == state_type(0u); + bool tick = kdd ? (state & tick_mask) == state_type(0u) : (state >> tick_shift) == state_type(0u); if (tick) advance_table(); } @@ -1288,25 +1033,19 @@ namespace pcg_detail { } public: - static constexpr size_t period_pow2() - { - return baseclass::period_pow2() + table_size*extvalclass::period_pow2(); + static constexpr size_t period_pow2() { + return baseclass::period_pow2() + table_size * extvalclass::period_pow2(); } - PCG_ALWAYS_INLINE result_type operator()() - { + PCG_ALWAYS_INLINE result_type operator()() { result_type rhs = get_extended_value(); result_type lhs = this->baseclass::operator()(); return lhs ^ rhs; } - result_type operator()(result_type upper_bound) - { - return bounded_rand(*this, upper_bound); - } + result_type operator()(result_type upper_bound) { return bounded_rand(*this, upper_bound); } - void set(result_type wanted) - { + void set(result_type wanted) { result_type& rhs = get_extended_value(); result_type lhs = this->baseclass::operator()(); rhs = lhs ^ wanted; @@ -1314,53 +1053,30 @@ namespace pcg_detail { void advance(state_type distance, bool forwards = true); - void backstep(state_type distance) - { - advance(distance, false); - } + void backstep(state_type distance) { advance(distance, false); } - extended(const result_type* data) - : baseclass() - { - datainit(data); - } + extended(const result_type* data) : baseclass() { datainit(data); } - extended(const result_type* data, state_type seed) - : baseclass(seed) - { - datainit(data); - } + extended(const result_type* data, state_type seed) : baseclass(seed) { datainit(data); } // This function may or may not exist. It thus has to be a template // to use SFINAE; users don't have to worry about its template-ness. template - extended(const result_type* data, state_type seed, - typename bc::stream_state stream_seed) - : baseclass(seed, stream_seed) - { + extended(const result_type* data, state_type seed, typename bc::stream_state stream_seed) + : baseclass(seed, stream_seed) { datainit(data); } - extended() - : baseclass() - { - selfinit(); - } + extended() : baseclass() { selfinit(); } - extended(state_type seed) - : baseclass(seed) - { - selfinit(); - } + extended(state_type seed) : baseclass(seed) { selfinit(); } // This function may or may not exist. It thus has to be a template // to use SFINAE; users don't have to worry about its template-ness. template - extended(state_type seed, typename bc::stream_state stream_seed) - : baseclass(seed, stream_seed) - { + extended(state_type seed, typename bc::stream_state stream_seed) : baseclass(seed, stream_seed) { selfinit(); } @@ -1369,61 +1085,41 @@ namespace pcg_detail { void datainit(const result_type* data); public: - - template::value - && !std::is_convertible::value>::type> - extended(SeedSeq&& seedSeq) - : baseclass(seedSeq) - { + template ::value && + !std::is_convertible::value>::type> + extended(SeedSeq&& seedSeq) : baseclass(seedSeq) { generate_to(seedSeq, data_); } - template - void seed(Args&&... args) - { - new (this) extended(std::forward(args)...); - } + template void seed(Args&&... args) { new (this) extended(std::forward(args)...); } - template - friend bool operator==(const extended&, - const extended&); + template + friend bool operator==(const extended&, + const extended&); - template - friend std::basic_ostream& - operator<<(std::basic_ostream& out, - const extended&); - - template - friend std::basic_istream& - operator>>(std::basic_istream& in, - extended&); + template + friend std::basic_ostream& + operator<<(std::basic_ostream& out, + const extended&); + template + friend std::basic_istream& + operator>>(std::basic_istream& in, + extended&); }; - - template - void extended::datainit( - const result_type* data) - { + template + void extended::datainit(const result_type* data) { for (size_t i = 0; i < table_size; ++i) data_[i] = data[i]; } - template - void extended::selfinit() - { + template + void extended::selfinit() { // We need to fill the extended table with something, and we have // very little provided data, so we use the base generator to // produce values. Although not ideal (use a seed sequence, folks!), @@ -1442,47 +1138,30 @@ namespace pcg_detail { } } - template - bool operator==(const extended& lhs, - const extended& rhs) - { + template + bool operator==(const extended& lhs, + const extended& rhs) { auto& base_lhs = static_cast(lhs); auto& base_rhs = static_cast(rhs); - return base_lhs == base_rhs - && std::equal( - std::begin(lhs.data_), std::end(lhs.data_), - std::begin(rhs.data_) - ); + return base_lhs == base_rhs && std::equal(std::begin(lhs.data_), std::end(lhs.data_), std::begin(rhs.data_)); } - template - inline bool operator!=(const extended& lhs, - const extended& rhs) - { + template + inline bool operator!=(const extended& lhs, + const extended& rhs) { return !operator==(lhs, rhs); } - template - std::basic_ostream& - operator<<(std::basic_ostream& out, - const extended& rng) - { + template + std::basic_ostream& + operator<<(std::basic_ostream& out, + const extended& rng) { auto orig_flags = out.flags(std::ios_base::dec | std::ios_base::left); auto space = out.widen(' '); auto orig_fill = out.fill(); - out << rng.multiplier() << space - << rng.increment() << space - << rng.state_; + out << rng.multiplier() << space << rng.increment() << space << rng.state_; for (const auto& datum : rng.data_) out << space << datum; @@ -1492,14 +1171,11 @@ namespace pcg_detail { return out; } - template - std::basic_istream& - operator>>(std::basic_istream& in, - extended& rng) - { + template + std::basic_istream& + operator>>(std::basic_istream& in, + extended& rng) { extended new_rng; auto& base_rng = static_cast(new_rng); in >> base_rng; @@ -1517,71 +1193,55 @@ namespace pcg_detail { rng = new_rng; - bail: + bail: in.flags(orig_flags); return in; } - - - template - void - extended::advance_table() - { + template + void extended::advance_table() { bool carry = false; for (size_t i = 0; i < table_size; ++i) { if (carry) { - carry = insideout::external_step(data_[i],i+1); + carry = insideout::external_step(data_[i], i + 1); } - bool carry2 = insideout::external_step(data_[i],i+1); + bool carry2 = insideout::external_step(data_[i], i + 1); carry = carry || carry2; } } - template - void - extended::advance_table( - state_type delta, bool isForwards) - { - typedef typename baseclass::state_type base_state_t; + template + void extended::advance_table(state_type delta, + bool isForwards) { + typedef typename baseclass::state_type base_state_t; typedef typename extvalclass::state_type ext_state_t; - constexpr bitcount_t basebits = sizeof(base_state_t)*8; - constexpr bitcount_t extbits = sizeof(ext_state_t)*8; - static_assert(basebits <= extbits || advance_pow2 > 0, - "Current implementation might overflow its carry"); + constexpr bitcount_t basebits = sizeof(base_state_t) * 8; + constexpr bitcount_t extbits = sizeof(ext_state_t) * 8; + static_assert(basebits <= extbits || advance_pow2 > 0, "Current implementation might overflow its carry"); base_state_t carry = 0; for (size_t i = 0; i < table_size; ++i) { base_state_t total_delta = carry + delta; - ext_state_t trunc_delta = ext_state_t(total_delta); + ext_state_t trunc_delta = ext_state_t(total_delta); if (basebits > extbits) { carry = total_delta >> extbits; } else { carry = 0; } - carry += - insideout::external_advance(data_[i],i+1, trunc_delta, isForwards); + carry += insideout::external_advance(data_[i], i + 1, trunc_delta, isForwards); } } - template - void extended::advance( - state_type distance, bool forwards) - { - static_assert(kdd, - "Efficient advance is too hard for non-kdd extension. " - "For a weak advance, cast to base class"); - state_type zero = - baseclass::is_mcg ? this->state_ & state_type(3U) : state_type(0U); + template + void extended::advance(state_type distance, bool forwards) { + static_assert(kdd, "Efficient advance is too hard for non-kdd extension. " + "For a weak advance, cast to base class"); + state_type zero = baseclass::is_mcg ? this->state_ & state_type(3U) : state_type(0U); if (may_tick) { - state_type ticks = distance >> (advance_pow2*may_tick); + state_type ticks = distance >> (advance_pow2 * may_tick); // ^-- stupidity to appease GCC // warnings - state_type adv_mask = - baseclass::is_mcg ? tick_mask << 2 : tick_mask; + state_type adv_mask = baseclass::is_mcg ? tick_mask << 2 : tick_mask; state_type next_advance_distance = this->distance(zero, adv_mask); if (!forwards) next_advance_distance = (-next_advance_distance) & tick_mask; @@ -1608,287 +1268,235 @@ namespace pcg_engines { using namespace pcg_detail; -/* Predefined types for XSH RS */ + /* Predefined types for XSH RS */ - typedef oneseq_base oneseq_xsh_rs_16_8; - typedef oneseq_base oneseq_xsh_rs_32_16; - typedef oneseq_base oneseq_xsh_rs_64_32; - typedef oneseq_base oneseq_xsh_rs_128_64; - typedef oneseq_base - cm_oneseq_xsh_rs_128_64; + typedef oneseq_base oneseq_xsh_rs_16_8; + typedef oneseq_base oneseq_xsh_rs_32_16; + typedef oneseq_base oneseq_xsh_rs_64_32; + typedef oneseq_base oneseq_xsh_rs_128_64; + typedef oneseq_base cm_oneseq_xsh_rs_128_64; - typedef unique_base unique_xsh_rs_16_8; - typedef unique_base unique_xsh_rs_32_16; - typedef unique_base unique_xsh_rs_64_32; - typedef unique_base unique_xsh_rs_128_64; - typedef unique_base - cm_unique_xsh_rs_128_64; + typedef unique_base unique_xsh_rs_16_8; + typedef unique_base unique_xsh_rs_32_16; + typedef unique_base unique_xsh_rs_64_32; + typedef unique_base unique_xsh_rs_128_64; + typedef unique_base cm_unique_xsh_rs_128_64; - typedef setseq_base setseq_xsh_rs_16_8; - typedef setseq_base setseq_xsh_rs_32_16; - typedef setseq_base setseq_xsh_rs_64_32; - typedef setseq_base setseq_xsh_rs_128_64; - typedef setseq_base - cm_setseq_xsh_rs_128_64; + typedef setseq_base setseq_xsh_rs_16_8; + typedef setseq_base setseq_xsh_rs_32_16; + typedef setseq_base setseq_xsh_rs_64_32; + typedef setseq_base setseq_xsh_rs_128_64; + typedef setseq_base cm_setseq_xsh_rs_128_64; - typedef mcg_base mcg_xsh_rs_16_8; - typedef mcg_base mcg_xsh_rs_32_16; - typedef mcg_base mcg_xsh_rs_64_32; - typedef mcg_base mcg_xsh_rs_128_64; - typedef mcg_base - cm_mcg_xsh_rs_128_64; + typedef mcg_base mcg_xsh_rs_16_8; + typedef mcg_base mcg_xsh_rs_32_16; + typedef mcg_base mcg_xsh_rs_64_32; + typedef mcg_base mcg_xsh_rs_128_64; + typedef mcg_base cm_mcg_xsh_rs_128_64; -/* Predefined types for XSH RR */ + /* Predefined types for XSH RR */ - typedef oneseq_base oneseq_xsh_rr_16_8; - typedef oneseq_base oneseq_xsh_rr_32_16; - typedef oneseq_base oneseq_xsh_rr_64_32; - typedef oneseq_base oneseq_xsh_rr_128_64; - typedef oneseq_base - cm_oneseq_xsh_rr_128_64; + typedef oneseq_base oneseq_xsh_rr_16_8; + typedef oneseq_base oneseq_xsh_rr_32_16; + typedef oneseq_base oneseq_xsh_rr_64_32; + typedef oneseq_base oneseq_xsh_rr_128_64; + typedef oneseq_base cm_oneseq_xsh_rr_128_64; - typedef unique_base unique_xsh_rr_16_8; - typedef unique_base unique_xsh_rr_32_16; - typedef unique_base unique_xsh_rr_64_32; - typedef unique_base unique_xsh_rr_128_64; - typedef unique_base - cm_unique_xsh_rr_128_64; + typedef unique_base unique_xsh_rr_16_8; + typedef unique_base unique_xsh_rr_32_16; + typedef unique_base unique_xsh_rr_64_32; + typedef unique_base unique_xsh_rr_128_64; + typedef unique_base cm_unique_xsh_rr_128_64; - typedef setseq_base setseq_xsh_rr_16_8; - typedef setseq_base setseq_xsh_rr_32_16; - typedef setseq_base setseq_xsh_rr_64_32; - typedef setseq_base setseq_xsh_rr_128_64; - typedef setseq_base - cm_setseq_xsh_rr_128_64; + typedef setseq_base setseq_xsh_rr_16_8; + typedef setseq_base setseq_xsh_rr_32_16; + typedef setseq_base setseq_xsh_rr_64_32; + typedef setseq_base setseq_xsh_rr_128_64; + typedef setseq_base cm_setseq_xsh_rr_128_64; - typedef mcg_base mcg_xsh_rr_16_8; - typedef mcg_base mcg_xsh_rr_32_16; - typedef mcg_base mcg_xsh_rr_64_32; - typedef mcg_base mcg_xsh_rr_128_64; - typedef mcg_base - cm_mcg_xsh_rr_128_64; + typedef mcg_base mcg_xsh_rr_16_8; + typedef mcg_base mcg_xsh_rr_32_16; + typedef mcg_base mcg_xsh_rr_64_32; + typedef mcg_base mcg_xsh_rr_128_64; + typedef mcg_base cm_mcg_xsh_rr_128_64; + /* Predefined types for RXS M XS */ -/* Predefined types for RXS M XS */ + typedef oneseq_base oneseq_rxs_m_xs_8_8; + typedef oneseq_base oneseq_rxs_m_xs_16_16; + typedef oneseq_base oneseq_rxs_m_xs_32_32; + typedef oneseq_base oneseq_rxs_m_xs_64_64; + typedef oneseq_base oneseq_rxs_m_xs_128_128; + typedef oneseq_base cm_oneseq_rxs_m_xs_128_128; - typedef oneseq_base oneseq_rxs_m_xs_8_8; - typedef oneseq_base oneseq_rxs_m_xs_16_16; - typedef oneseq_base oneseq_rxs_m_xs_32_32; - typedef oneseq_base oneseq_rxs_m_xs_64_64; - typedef oneseq_base - oneseq_rxs_m_xs_128_128; - typedef oneseq_base - cm_oneseq_rxs_m_xs_128_128; - - typedef unique_base unique_rxs_m_xs_8_8; + typedef unique_base unique_rxs_m_xs_8_8; typedef unique_base unique_rxs_m_xs_16_16; typedef unique_base unique_rxs_m_xs_32_32; typedef unique_base unique_rxs_m_xs_64_64; typedef unique_base unique_rxs_m_xs_128_128; - typedef unique_base - cm_unique_rxs_m_xs_128_128; + typedef unique_base cm_unique_rxs_m_xs_128_128; - typedef setseq_base setseq_rxs_m_xs_8_8; + typedef setseq_base setseq_rxs_m_xs_8_8; typedef setseq_base setseq_rxs_m_xs_16_16; typedef setseq_base setseq_rxs_m_xs_32_32; typedef setseq_base setseq_rxs_m_xs_64_64; typedef setseq_base setseq_rxs_m_xs_128_128; - typedef setseq_base - cm_setseq_rxs_m_xs_128_128; + typedef setseq_base cm_setseq_rxs_m_xs_128_128; // MCG versions don't make sense here, so aren't defined. -/* Predefined types for RXS M */ + /* Predefined types for RXS M */ - typedef oneseq_base oneseq_rxs_m_16_8; - typedef oneseq_base oneseq_rxs_m_32_16; - typedef oneseq_base oneseq_rxs_m_64_32; - typedef oneseq_base oneseq_rxs_m_128_64; - typedef oneseq_base - cm_oneseq_rxs_m_128_64; + typedef oneseq_base oneseq_rxs_m_16_8; + typedef oneseq_base oneseq_rxs_m_32_16; + typedef oneseq_base oneseq_rxs_m_64_32; + typedef oneseq_base oneseq_rxs_m_128_64; + typedef oneseq_base cm_oneseq_rxs_m_128_64; - typedef unique_base unique_rxs_m_16_8; - typedef unique_base unique_rxs_m_32_16; - typedef unique_base unique_rxs_m_64_32; - typedef unique_base unique_rxs_m_128_64; - typedef unique_base - cm_unique_rxs_m_128_64; + typedef unique_base unique_rxs_m_16_8; + typedef unique_base unique_rxs_m_32_16; + typedef unique_base unique_rxs_m_64_32; + typedef unique_base unique_rxs_m_128_64; + typedef unique_base cm_unique_rxs_m_128_64; - typedef setseq_base setseq_rxs_m_16_8; - typedef setseq_base setseq_rxs_m_32_16; - typedef setseq_base setseq_rxs_m_64_32; - typedef setseq_base setseq_rxs_m_128_64; - typedef setseq_base - cm_setseq_rxs_m_128_64; + typedef setseq_base setseq_rxs_m_16_8; + typedef setseq_base setseq_rxs_m_32_16; + typedef setseq_base setseq_rxs_m_64_32; + typedef setseq_base setseq_rxs_m_128_64; + typedef setseq_base cm_setseq_rxs_m_128_64; - typedef mcg_base mcg_rxs_m_16_8; - typedef mcg_base mcg_rxs_m_32_16; - typedef mcg_base mcg_rxs_m_64_32; - typedef mcg_base mcg_rxs_m_128_64; - typedef mcg_base - cm_mcg_rxs_m_128_64; + typedef mcg_base mcg_rxs_m_16_8; + typedef mcg_base mcg_rxs_m_32_16; + typedef mcg_base mcg_rxs_m_64_32; + typedef mcg_base mcg_rxs_m_128_64; + typedef mcg_base cm_mcg_rxs_m_128_64; -/* Predefined types for DXSM */ + /* Predefined types for DXSM */ - typedef oneseq_base oneseq_dxsm_16_8; - typedef oneseq_base oneseq_dxsm_32_16; - typedef oneseq_base oneseq_dxsm_64_32; - typedef oneseq_base oneseq_dxsm_128_64; - typedef oneseq_base - cm_oneseq_dxsm_128_64; + typedef oneseq_base oneseq_dxsm_16_8; + typedef oneseq_base oneseq_dxsm_32_16; + typedef oneseq_base oneseq_dxsm_64_32; + typedef oneseq_base oneseq_dxsm_128_64; + typedef oneseq_base cm_oneseq_dxsm_128_64; - typedef unique_base unique_dxsm_16_8; - typedef unique_base unique_dxsm_32_16; - typedef unique_base unique_dxsm_64_32; - typedef unique_base unique_dxsm_128_64; - typedef unique_base - cm_unique_dxsm_128_64; + typedef unique_base unique_dxsm_16_8; + typedef unique_base unique_dxsm_32_16; + typedef unique_base unique_dxsm_64_32; + typedef unique_base unique_dxsm_128_64; + typedef unique_base cm_unique_dxsm_128_64; - typedef setseq_base setseq_dxsm_16_8; - typedef setseq_base setseq_dxsm_32_16; - typedef setseq_base setseq_dxsm_64_32; - typedef setseq_base setseq_dxsm_128_64; - typedef setseq_base - cm_setseq_dxsm_128_64; + typedef setseq_base setseq_dxsm_16_8; + typedef setseq_base setseq_dxsm_32_16; + typedef setseq_base setseq_dxsm_64_32; + typedef setseq_base setseq_dxsm_128_64; + typedef setseq_base cm_setseq_dxsm_128_64; - typedef mcg_base mcg_dxsm_16_8; - typedef mcg_base mcg_dxsm_32_16; - typedef mcg_base mcg_dxsm_64_32; - typedef mcg_base mcg_dxsm_128_64; - typedef mcg_base - cm_mcg_dxsm_128_64; + typedef mcg_base mcg_dxsm_16_8; + typedef mcg_base mcg_dxsm_32_16; + typedef mcg_base mcg_dxsm_64_32; + typedef mcg_base mcg_dxsm_128_64; + typedef mcg_base cm_mcg_dxsm_128_64; -/* Predefined types for XSL RR (only defined for "large" types) */ + /* Predefined types for XSL RR (only defined for "large" types) */ - typedef oneseq_base oneseq_xsl_rr_64_32; - typedef oneseq_base oneseq_xsl_rr_128_64; - typedef oneseq_base - cm_oneseq_xsl_rr_128_64; + typedef oneseq_base oneseq_xsl_rr_64_32; + typedef oneseq_base oneseq_xsl_rr_128_64; + typedef oneseq_base cm_oneseq_xsl_rr_128_64; - typedef unique_base unique_xsl_rr_64_32; - typedef unique_base unique_xsl_rr_128_64; - typedef unique_base - cm_unique_xsl_rr_128_64; + typedef unique_base unique_xsl_rr_64_32; + typedef unique_base unique_xsl_rr_128_64; + typedef unique_base cm_unique_xsl_rr_128_64; - typedef setseq_base setseq_xsl_rr_64_32; - typedef setseq_base setseq_xsl_rr_128_64; - typedef setseq_base - cm_setseq_xsl_rr_128_64; + typedef setseq_base setseq_xsl_rr_64_32; + typedef setseq_base setseq_xsl_rr_128_64; + typedef setseq_base cm_setseq_xsl_rr_128_64; - typedef mcg_base mcg_xsl_rr_64_32; - typedef mcg_base mcg_xsl_rr_128_64; - typedef mcg_base - cm_mcg_xsl_rr_128_64; + typedef mcg_base mcg_xsl_rr_64_32; + typedef mcg_base mcg_xsl_rr_128_64; + typedef mcg_base cm_mcg_xsl_rr_128_64; + /* Predefined types for XSL RR RR (only defined for "large" types) */ -/* Predefined types for XSL RR RR (only defined for "large" types) */ + typedef oneseq_base oneseq_xsl_rr_rr_64_64; + typedef oneseq_base oneseq_xsl_rr_rr_128_128; + typedef oneseq_base cm_oneseq_xsl_rr_rr_128_128; - typedef oneseq_base - oneseq_xsl_rr_rr_64_64; - typedef oneseq_base - oneseq_xsl_rr_rr_128_128; - typedef oneseq_base - cm_oneseq_xsl_rr_rr_128_128; + typedef unique_base unique_xsl_rr_rr_64_64; + typedef unique_base unique_xsl_rr_rr_128_128; + typedef unique_base cm_unique_xsl_rr_rr_128_128; - typedef unique_base - unique_xsl_rr_rr_64_64; - typedef unique_base - unique_xsl_rr_rr_128_128; - typedef unique_base - cm_unique_xsl_rr_rr_128_128; - - typedef setseq_base - setseq_xsl_rr_rr_64_64; - typedef setseq_base - setseq_xsl_rr_rr_128_128; - typedef setseq_base - cm_setseq_xsl_rr_rr_128_128; + typedef setseq_base setseq_xsl_rr_rr_64_64; + typedef setseq_base setseq_xsl_rr_rr_128_128; + typedef setseq_base cm_setseq_xsl_rr_rr_128_128; // MCG versions don't make sense here, so aren't defined. -/* Extended generators */ + /* Extended generators */ - template - using ext_std8 = extended; + template + using ext_std8 = extended; - template - using ext_std16 = extended; + template + using ext_std16 = extended; - template - using ext_std32 = extended; - - template - using ext_std64 = extended; + template + using ext_std32 = extended; + template + using ext_std64 = extended; template - using ext_oneseq_rxs_m_xs_32_32 = - ext_std32; + using ext_oneseq_rxs_m_xs_32_32 = ext_std32; template - using ext_mcg_xsh_rs_64_32 = - ext_std32; + using ext_mcg_xsh_rs_64_32 = ext_std32; template - using ext_oneseq_xsh_rs_64_32 = - ext_std32; + using ext_oneseq_xsh_rs_64_32 = ext_std32; template - using ext_setseq_xsh_rr_64_32 = - ext_std32; + using ext_setseq_xsh_rr_64_32 = ext_std32; template - using ext_mcg_xsl_rr_128_64 = - ext_std64; + using ext_mcg_xsl_rr_128_64 = ext_std64; template - using ext_oneseq_xsl_rr_128_64 = - ext_std64; + using ext_oneseq_xsl_rr_128_64 = ext_std64; template - using ext_setseq_xsl_rr_128_64 = - ext_std64; + using ext_setseq_xsl_rr_128_64 = ext_std64; } // namespace pcg_engines -typedef pcg_engines::setseq_xsh_rr_64_32 pcg32; -typedef pcg_engines::oneseq_xsh_rr_64_32 pcg32_oneseq; -typedef pcg_engines::unique_xsh_rr_64_32 pcg32_unique; -typedef pcg_engines::mcg_xsh_rs_64_32 pcg32_fast; +typedef pcg_engines::setseq_xsh_rr_64_32 pcg32; +typedef pcg_engines::oneseq_xsh_rr_64_32 pcg32_oneseq; +typedef pcg_engines::unique_xsh_rr_64_32 pcg32_unique; +typedef pcg_engines::mcg_xsh_rs_64_32 pcg32_fast; -typedef pcg_engines::setseq_xsl_rr_128_64 pcg64; -typedef pcg_engines::oneseq_xsl_rr_128_64 pcg64_oneseq; -typedef pcg_engines::unique_xsl_rr_128_64 pcg64_unique; -typedef pcg_engines::mcg_xsl_rr_128_64 pcg64_fast; +typedef pcg_engines::setseq_xsl_rr_128_64 pcg64; +typedef pcg_engines::oneseq_xsl_rr_128_64 pcg64_oneseq; +typedef pcg_engines::unique_xsl_rr_128_64 pcg64_unique; +typedef pcg_engines::mcg_xsl_rr_128_64 pcg64_fast; -typedef pcg_engines::setseq_rxs_m_xs_8_8 pcg8_once_insecure; -typedef pcg_engines::setseq_rxs_m_xs_16_16 pcg16_once_insecure; -typedef pcg_engines::setseq_rxs_m_xs_32_32 pcg32_once_insecure; -typedef pcg_engines::setseq_rxs_m_xs_64_64 pcg64_once_insecure; -typedef pcg_engines::setseq_xsl_rr_rr_128_128 pcg128_once_insecure; - -typedef pcg_engines::oneseq_rxs_m_xs_8_8 pcg8_oneseq_once_insecure; -typedef pcg_engines::oneseq_rxs_m_xs_16_16 pcg16_oneseq_once_insecure; -typedef pcg_engines::oneseq_rxs_m_xs_32_32 pcg32_oneseq_once_insecure; -typedef pcg_engines::oneseq_rxs_m_xs_64_64 pcg64_oneseq_once_insecure; -typedef pcg_engines::oneseq_xsl_rr_rr_128_128 pcg128_oneseq_once_insecure; +typedef pcg_engines::setseq_rxs_m_xs_8_8 pcg8_once_insecure; +typedef pcg_engines::setseq_rxs_m_xs_16_16 pcg16_once_insecure; +typedef pcg_engines::setseq_rxs_m_xs_32_32 pcg32_once_insecure; +typedef pcg_engines::setseq_rxs_m_xs_64_64 pcg64_once_insecure; +typedef pcg_engines::setseq_xsl_rr_rr_128_128 pcg128_once_insecure; +typedef pcg_engines::oneseq_rxs_m_xs_8_8 pcg8_oneseq_once_insecure; +typedef pcg_engines::oneseq_rxs_m_xs_16_16 pcg16_oneseq_once_insecure; +typedef pcg_engines::oneseq_rxs_m_xs_32_32 pcg32_oneseq_once_insecure; +typedef pcg_engines::oneseq_rxs_m_xs_64_64 pcg64_oneseq_once_insecure; +typedef pcg_engines::oneseq_xsl_rr_rr_128_128 pcg128_oneseq_once_insecure; // These two extended RNGs provide two-dimensionally equidistributed // 32-bit generators. pcg32_k2_fast occupies the same space as pcg64, // and can be called twice to generate 64 bits, but does not required // 128-bit math; on 32-bit systems, it's faster than pcg64 as well. -typedef pcg_engines::ext_setseq_xsh_rr_64_32<1,16,true> pcg32_k2; -typedef pcg_engines::ext_oneseq_xsh_rs_64_32<1,32,true> pcg32_k2_fast; +typedef pcg_engines::ext_setseq_xsh_rr_64_32<1, 16, true> pcg32_k2; +typedef pcg_engines::ext_oneseq_xsh_rs_64_32<1, 32, true> pcg32_k2_fast; // These eight extended RNGs have about as much state as arc4random // @@ -1897,21 +1505,21 @@ typedef pcg_engines::ext_oneseq_xsh_rs_64_32<1,32,true> pcg32_k2_fast; // // (just how good the cryptographic security is is an open question) -typedef pcg_engines::ext_setseq_xsh_rr_64_32<6,16,true> pcg32_k64; -typedef pcg_engines::ext_mcg_xsh_rs_64_32<6,32,true> pcg32_k64_oneseq; -typedef pcg_engines::ext_oneseq_xsh_rs_64_32<6,32,true> pcg32_k64_fast; +typedef pcg_engines::ext_setseq_xsh_rr_64_32<6, 16, true> pcg32_k64; +typedef pcg_engines::ext_mcg_xsh_rs_64_32<6, 32, true> pcg32_k64_oneseq; +typedef pcg_engines::ext_oneseq_xsh_rs_64_32<6, 32, true> pcg32_k64_fast; -typedef pcg_engines::ext_setseq_xsh_rr_64_32<6,16,false> pcg32_c64; -typedef pcg_engines::ext_oneseq_xsh_rs_64_32<6,32,false> pcg32_c64_oneseq; -typedef pcg_engines::ext_mcg_xsh_rs_64_32<6,32,false> pcg32_c64_fast; +typedef pcg_engines::ext_setseq_xsh_rr_64_32<6, 16, false> pcg32_c64; +typedef pcg_engines::ext_oneseq_xsh_rs_64_32<6, 32, false> pcg32_c64_oneseq; +typedef pcg_engines::ext_mcg_xsh_rs_64_32<6, 32, false> pcg32_c64_fast; -typedef pcg_engines::ext_setseq_xsl_rr_128_64<5,16,true> pcg64_k32; -typedef pcg_engines::ext_oneseq_xsl_rr_128_64<5,128,true> pcg64_k32_oneseq; -typedef pcg_engines::ext_mcg_xsl_rr_128_64<5,128,true> pcg64_k32_fast; +typedef pcg_engines::ext_setseq_xsl_rr_128_64<5, 16, true> pcg64_k32; +typedef pcg_engines::ext_oneseq_xsl_rr_128_64<5, 128, true> pcg64_k32_oneseq; +typedef pcg_engines::ext_mcg_xsl_rr_128_64<5, 128, true> pcg64_k32_fast; -typedef pcg_engines::ext_setseq_xsl_rr_128_64<5,16,false> pcg64_c32; -typedef pcg_engines::ext_oneseq_xsl_rr_128_64<5,128,false> pcg64_c32_oneseq; -typedef pcg_engines::ext_mcg_xsl_rr_128_64<5,128,false> pcg64_c32_fast; +typedef pcg_engines::ext_setseq_xsl_rr_128_64<5, 16, false> pcg64_c32; +typedef pcg_engines::ext_oneseq_xsl_rr_128_64<5, 128, false> pcg64_c32_oneseq; +typedef pcg_engines::ext_mcg_xsl_rr_128_64<5, 128, false> pcg64_c32_fast; // These eight extended RNGs have more state than the Mersenne twister // @@ -1920,28 +1528,28 @@ typedef pcg_engines::ext_mcg_xsl_rr_128_64<5,128,false> pcg64_c32_fast; // // (just how good the cryptographic security is is an open question) -typedef pcg_engines::ext_setseq_xsh_rr_64_32<10,16,true> pcg32_k1024; -typedef pcg_engines::ext_oneseq_xsh_rs_64_32<10,32,true> pcg32_k1024_fast; +typedef pcg_engines::ext_setseq_xsh_rr_64_32<10, 16, true> pcg32_k1024; +typedef pcg_engines::ext_oneseq_xsh_rs_64_32<10, 32, true> pcg32_k1024_fast; -typedef pcg_engines::ext_setseq_xsh_rr_64_32<10,16,false> pcg32_c1024; -typedef pcg_engines::ext_oneseq_xsh_rs_64_32<10,32,false> pcg32_c1024_fast; +typedef pcg_engines::ext_setseq_xsh_rr_64_32<10, 16, false> pcg32_c1024; +typedef pcg_engines::ext_oneseq_xsh_rs_64_32<10, 32, false> pcg32_c1024_fast; -typedef pcg_engines::ext_setseq_xsl_rr_128_64<10,16,true> pcg64_k1024; -typedef pcg_engines::ext_oneseq_xsl_rr_128_64<10,128,true> pcg64_k1024_fast; +typedef pcg_engines::ext_setseq_xsl_rr_128_64<10, 16, true> pcg64_k1024; +typedef pcg_engines::ext_oneseq_xsl_rr_128_64<10, 128, true> pcg64_k1024_fast; -typedef pcg_engines::ext_setseq_xsl_rr_128_64<10,16,false> pcg64_c1024; -typedef pcg_engines::ext_oneseq_xsl_rr_128_64<10,128,false> pcg64_c1024_fast; +typedef pcg_engines::ext_setseq_xsl_rr_128_64<10, 16, false> pcg64_c1024; +typedef pcg_engines::ext_oneseq_xsl_rr_128_64<10, 128, false> pcg64_c1024_fast; // These generators have an insanely huge period (2^524352), and is suitable // for silly party tricks, such as dumping out 64 KB ZIP files at an arbitrary // point in the future. [Actually, over the full period of the generator, it // will produce every 64 KB ZIP file 2^64 times!] -typedef pcg_engines::ext_setseq_xsh_rr_64_32<14,16,true> pcg32_k16384; -typedef pcg_engines::ext_oneseq_xsh_rs_64_32<14,32,true> pcg32_k16384_fast; +typedef pcg_engines::ext_setseq_xsh_rr_64_32<14, 16, true> pcg32_k16384; +typedef pcg_engines::ext_oneseq_xsh_rs_64_32<14, 32, true> pcg32_k16384_fast; #ifdef _MSC_VER -#pragma warning(default:4146) +#pragma warning(default : 4146) #endif #endif // PCG_RAND_HPP_INCLUDED