9#ifndef pRC_CORE_RANDOM_ENGINES_THREEFRY_H
10#define pRC_CORE_RANDOM_ENGINES_THREEFRY_H
20 template<Size Rounds,
class U = Seed>
26 static constexpr auto min()
31 static constexpr auto max()
38 return 32 /
sizeof(U);
67 seed(seq.template generate<8>());
75 if(mChunkCounter == 0)
81 return reinterpret_cast<U
const *
>(mCipher.data())[mChunkCounter];
98 incrementCounter(++
z);
119 if(mChunkCounter != rhs.mChunkCounter)
126 if(mCounter[
i] != rhs.mCounter[
i])
130 if(mKey[
i] != rhs.mKey[
i])
134 if(mCipher[
i] != rhs.mCipher[
i])
144 return !(*
this == rhs);
152 mKey[
i] = (
static_cast<std::uint64_t
>(seq[2 *
i]) << 32) |
156 0x1BD11BDAA9FC1A22 ^ mKey[0] ^ mKey[1] ^ mKey[2] ^ mKey[3];
162 constexpr void resetCounter()
171 constexpr void incrementCounter()
194 constexpr void incrementCounter(std::uint64_t
const z)
196 if(
z > NumericLimits<std::uint64_t>::max() - mCounter[0])
211 constexpr void encryptCounter()
213 auto const mix = [](
auto &
x,
auto &
y, std::uint8_t
const bits)
220 auto const add = [](
auto &cipher,
auto const &key,
221 auto const offset,
auto const cycle)
224 [&cipher, &key, &offset](
auto const i)
226 cipher[
i] += key[(offset +
i) % 5];
235 mCipher[
i] = mCounter[
i];
241 mCipher[
i] += mKey[
i];
247 [
this, &mix, &add, &cycle](
auto const i)
251 mix(mCipher[0], mCipher[1], 14U);
252 mix(mCipher[2], mCipher[3], 16U);
257 mix(mCipher[0], mCipher[3], 52U);
258 mix(mCipher[2], mCipher[1], 57U);
263 mix(mCipher[0], mCipher[1], 23U);
264 mix(mCipher[2], mCipher[3], 40U);
269 mix(mCipher[0], mCipher[3], 5U);
270 mix(mCipher[2], mCipher[1], 37U);
271 add(mCipher, mKey, (
i + 1) / 4, ++cycle);
276 mix(mCipher[0], mCipher[1], 25U);
277 mix(mCipher[2], mCipher[3], 33U);
282 mix(mCipher[0], mCipher[3], 46U);
283 mix(mCipher[2], mCipher[1], 12U);
288 mix(mCipher[0], mCipher[1], 58U);
289 mix(mCipher[2], mCipher[3], 22U);
294 mix(mCipher[0], mCipher[3], 32U);
295 mix(mCipher[2], mCipher[1], 32U);
296 add(mCipher, mKey, (
i + 1) / 4, ++cycle);
305 std::uint8_t mChunkCounter;
Definition declarations.hpp:12
Definition threefry.hpp:22
constexpr void discard(std::uint64_t z)
Definition threefry.hpp:84
constexpr auto operator!=(const Threefry &rhs)
Definition threefry.hpp:142
constexpr Threefry & operator=(Threefry const &) &=default
constexpr Threefry & operator=(Threefry &&) &=default
constexpr Threefry(Threefry &&)=default
static constexpr auto max()
Definition threefry.hpp:31
constexpr void seed()
Definition threefry.hpp:59
constexpr void seed(SeedSequence< S > const &seq)
Definition threefry.hpp:65
Threefry(SeedSequence< S > const &seq)
Definition threefry.hpp:54
constexpr auto operator==(const Threefry &rhs)
Definition threefry.hpp:117
static constexpr auto min()
Definition threefry.hpp:26
U Type
Definition threefry.hpp:24
constexpr Threefry(Threefry const &)=default
static constexpr auto samplesPerBlock()
Definition threefry.hpp:36
constexpr void advance(std::uint64_t const z)
Definition threefry.hpp:102
Threefry()
Definition threefry.hpp:48
constexpr U operator()()
Definition threefry.hpp:70
int i
Definition gmock-matchers-comparisons_test.cc:603
Uncopyable z
Definition gmock-matchers-containers_test.cc:378
const double y
Definition gmock-matchers-containers_test.cc:377
int x
Definition gmock-matchers-containers_test.cc:376
Definition cholesky.hpp:10
Size Index
Definition basics.hpp:32
std::size_t Size
Definition basics.hpp:31
static constexpr auto bitRotateLeft(TA const value, TB count)
Definition bit_rotate_left.hpp:12
CommonArray< Allocation::Stack, T, Ns... > StackArray
Definition declarations.hpp:15
static constexpr auto range(F &&f, Xs &&...args)
Definition range.hpp:18