Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/REX/TRandom.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ namespace REX
using result_type = std::uint64_t;

TRandomDistribution() = delete;
TRandomDistribution(std::vector<std::uint32_t>& a_weights);
TRandomDistribution(std::uint32_t a_seed, std::vector<std::uint32_t>& a_weights);
TRandomDistribution(std::uint64_t a_seed, std::vector<std::uint32_t>& a_weights);
TRandomDistribution(const std::vector<std::uint32_t>& a_weights);
TRandomDistribution(std::uint32_t a_seed, const std::vector<std::uint32_t>& a_weights);
TRandomDistribution(std::uint64_t a_seed, const std::vector<std::uint32_t>& a_weights);

static constexpr result_type min() noexcept { return std::numeric_limits<result_type>::min(); }
static constexpr result_type max() noexcept { return std::numeric_limits<result_type>::max(); }
Expand Down
62 changes: 31 additions & 31 deletions src/REX/TRandom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,37 @@
return dist(*reinterpret_cast<XoshiroCpp::Xoshiro256StarStar*>(m_rng)); \
}

# define REX_DEFINE_RANDOM_DIST_FUNCTIONS(T) \
template <> \
TRandomDistribution<T>::TRandomDistribution(std::vector<std::uint32_t>& a_weights) : \
m_dist(a_weights.begin(), a_weights.end()) \
{ \
XoshiroCpp::Xoshiro256StarStar rng(std::chrono::steady_clock::now().time_since_epoch().count()); \
std::memcpy(&m_rng, &rng, sizeof(m_rng)); \
} \
template <> \
TRandomDistribution<T>::TRandomDistribution(std::uint32_t a_seed, std::vector<std::uint32_t>& a_weights) : \
m_dist(a_weights.begin(), a_weights.end()) \
{ \
XoshiroCpp::Xoshiro256StarStar rng(a_seed); \
std::memcpy(&m_rng, &rng, sizeof(m_rng)); \
} \
template <> \
TRandomDistribution<T>::TRandomDistribution(std::uint64_t a_seed, std::vector<std::uint32_t>& a_weights) : \
m_dist(a_weights.begin(), a_weights.end()) \
{ \
XoshiroCpp::Xoshiro256StarStar rng(a_seed); \
std::memcpy(&m_rng, &rng, sizeof(m_rng)); \
} \
template <> \
TRandomDistribution<T>::result_type TRandomDistribution<T>::operator()() noexcept \
{ \
return (*reinterpret_cast<XoshiroCpp::Xoshiro256StarStar*>(m_rng))(); \
} \
template <> \
T TRandomDistribution<T>::Generate() \
{ \
return m_dist(*reinterpret_cast<XoshiroCpp::Xoshiro256StarStar*>(m_rng)); \
# define REX_DEFINE_RANDOM_DIST_FUNCTIONS(T) \
template <> \
TRandomDistribution<T>::TRandomDistribution(const std::vector<std::uint32_t>& a_weights) : \
m_dist(a_weights.begin(), a_weights.end()) \
{ \
XoshiroCpp::Xoshiro256StarStar rng(std::chrono::steady_clock::now().time_since_epoch().count()); \
std::memcpy(&m_rng, &rng, sizeof(m_rng)); \
} \
template <> \
TRandomDistribution<T>::TRandomDistribution(std::uint32_t a_seed, const std::vector<std::uint32_t>& a_weights) : \
m_dist(a_weights.begin(), a_weights.end()) \
{ \
XoshiroCpp::Xoshiro256StarStar rng(a_seed); \
std::memcpy(&m_rng, &rng, sizeof(m_rng)); \
} \
template <> \
TRandomDistribution<T>::TRandomDistribution(std::uint64_t a_seed, const std::vector<std::uint32_t>& a_weights) : \
m_dist(a_weights.begin(), a_weights.end()) \
{ \
XoshiroCpp::Xoshiro256StarStar rng(a_seed); \
std::memcpy(&m_rng, &rng, sizeof(m_rng)); \
} \
template <> \
TRandomDistribution<T>::result_type TRandomDistribution<T>::operator()() noexcept \
{ \
return (*reinterpret_cast<XoshiroCpp::Xoshiro256StarStar*>(m_rng))(); \
} \
template <> \
T TRandomDistribution<T>::Generate() \
{ \
return m_dist(*reinterpret_cast<XoshiroCpp::Xoshiro256StarStar*>(m_rng)); \
}

namespace REX
Expand Down
Loading