diff --git a/include/REX/TRandom.h b/include/REX/TRandom.h index 7edd3ff..acb8a1f 100644 --- a/include/REX/TRandom.h +++ b/include/REX/TRandom.h @@ -35,9 +35,9 @@ namespace REX using result_type = std::uint64_t; TRandomDistribution() = delete; - TRandomDistribution(std::vector& a_weights); - TRandomDistribution(std::uint32_t a_seed, std::vector& a_weights); - TRandomDistribution(std::uint64_t a_seed, std::vector& a_weights); + TRandomDistribution(const std::vector& a_weights); + TRandomDistribution(std::uint32_t a_seed, const std::vector& a_weights); + TRandomDistribution(std::uint64_t a_seed, const std::vector& a_weights); static constexpr result_type min() noexcept { return std::numeric_limits::min(); } static constexpr result_type max() noexcept { return std::numeric_limits::max(); } diff --git a/src/REX/TRandom.cpp b/src/REX/TRandom.cpp index 08f9bd7..3b1776b 100644 --- a/src/REX/TRandom.cpp +++ b/src/REX/TRandom.cpp @@ -35,37 +35,37 @@ return dist(*reinterpret_cast(m_rng)); \ } -# define REX_DEFINE_RANDOM_DIST_FUNCTIONS(T) \ - template <> \ - TRandomDistribution::TRandomDistribution(std::vector& 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::TRandomDistribution(std::uint32_t a_seed, std::vector& 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::TRandomDistribution(std::uint64_t a_seed, std::vector& 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::result_type TRandomDistribution::operator()() noexcept \ - { \ - return (*reinterpret_cast(m_rng))(); \ - } \ - template <> \ - T TRandomDistribution::Generate() \ - { \ - return m_dist(*reinterpret_cast(m_rng)); \ +# define REX_DEFINE_RANDOM_DIST_FUNCTIONS(T) \ + template <> \ + TRandomDistribution::TRandomDistribution(const std::vector& 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::TRandomDistribution(std::uint32_t a_seed, const std::vector& 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::TRandomDistribution(std::uint64_t a_seed, const std::vector& 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::result_type TRandomDistribution::operator()() noexcept \ + { \ + return (*reinterpret_cast(m_rng))(); \ + } \ + template <> \ + T TRandomDistribution::Generate() \ + { \ + return m_dist(*reinterpret_cast(m_rng)); \ } namespace REX