Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TMt19937.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/primitive_type.h>
6
7#include <random>
8#include <type_traits>
9
10namespace ph::math
11{
12
15template<typename Bits>
16class TMt19937 final : public TUniformRandomBitGenerator<TMt19937<Bits>, Bits>
17{
18 static_assert(std::is_same_v<Bits, uint32> || std::is_same_v<Bits, uint64>,
19 "Supports only `uint32` and `uint64` bits types.");
20
21public:
23
24 explicit TMt19937(Bits seed);
25
26 Bits impl_generate();
27 void impl_jumpAhead(uint64 distance);
28
29private:
30 // There are 32 & 64 bit versions, select the one based on `BitsT`
31 using StdGeneratorType = std::conditional_t<std::is_same_v<Bits, uint32>,
32 std::mt19937, std::mt19937_64>;
33
34 StdGeneratorType m_generator;
35};
36
37template<typename Bits>
38inline TMt19937<Bits>::TMt19937(const Bits seed)
39 : m_generator(seed)
40{}
41
42template<typename Bits>
44{
45 return static_cast<Bits>(m_generator());
46}
47
48template<typename Bits>
49inline void TMt19937<Bits>::impl_jumpAhead(const uint64 distance)
50{
51 m_generator.discard(distance);
52}
53
54}// end namespace ph::math
Standard Mersenne Twister generator.
Definition TMt19937.h:17
void impl_jumpAhead(uint64 distance)
Definition TMt19937.h:49
Bits impl_generate()
Definition TMt19937.h:43
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TMt19937)
TMt19937(Bits seed)
Definition TMt19937.h:38
Definition TUniformRandomBitGenerator.h:30
Math functions and utilities.
Definition TransformInfo.h:10