29 #ifndef SOLIDUTILS_INCLUDE_FASTINTDISTRIBUTION_HPP 30 #define SOLIDUTILS_INCLUDE_FASTINTDISTRIBUTION_HPP 61 m_range(static_cast<uint64_t>(max-min)+1)
78 static_assert(std::numeric_limits<uint64_t>::max() > \
79 static_cast<uint64_t>(RNG::max() - RNG::min()), \
80 "Unhandled full 64 bit range.");
82 constexpr uint64_t RNG_RANGE =
static_cast<uint64_t
>(RNG::max() - RNG::min()) + 1;
84 uint64_t
const width = m_range / RNG_RANGE;
87 for (uint64_t i = 0; i <= width; ++i) {
88 num *=
static_cast<uint64_t
>(RNG_RANGE);
89 num +=
static_cast<uint64_t
>(rng() - RNG::min());
93 return static_cast<T
>(num) + m_min;
FastIntDistribution(T const min, T const max)
Create a new FastIntDistribution which will result in numbers [min,max].
Definition: FastIntDistribution.hpp:57
T operator()(RNG &rng)
Generate a number in the range of [min, max]. The distribution may not be uniform, particularily for larger ranges.
Definition: FastIntDistribution.hpp:76
This distribution is designed to be fast and consistent across platforms. However, it will not be uniform.
Definition: FastIntDistribution.hpp:47