class RangeRandomEngineBase
{
protected:
static inline std::mt19937 rdEngine{ std::random_device{}() };
};
template <typename T, typename StepType, typename ValueType = std::common_type_t<T, StepType>)
class Range : RangeRandomEngineBase
{
/*...*/
public:
using value_type = ValueType;
/*...*/
}
template<typename T, typename StepType>
Range(T start, T end, StepType step);
Construct a Range
class representing [start, end). When incremented, the current
value is incremented with step
. Note: according to deduction rules, start
and end
must have the same type.
value_type operator*() const;
Returns the current
value.
Range<T, StepType, ValueType> begin();
Returns *this
unchanged.
value_type end();
Returns the end
value.
auto steps() const;
Returns the number of ramaining steps to go in the current Range
.
bool operator!=(Range rhs) const; //1
bool operator!=(value_type value) const; //2
- Returns
this->current
=?=rhs.current
- Returns
this->current
=?=value
template<typename Num, typename = std::enable_if_t<std::is_arithmetic_v<Num>>>
bool operator==(Num number) const;
Returns whether this->current
<=number
<=this->end
, only instantiated when number
is a number type.
Range& operator++(); //1
Range& operator+=(unsigned steps); //2
- increment
*this
- increment
*this
steps
times
value_type rand(); //1
template<typename Container>
void fillRand(Container& container); //2
template<typename Container>
void fillRand(Container& container, size_t count); //3
template<typename InputIt>
void fillRand(InputIt begin, InputIt end); //4
value_type randFast() const; //5
template<typename Container>
void fillRandFast(Container& container); //6
template<typename Container>
void fillRandFast(Container& container, size_t count); //7
template<typename InputIt>
void fillRandFast(InputIt begin, InputIt end); //8
- 1-4 uses
std::uniform_<T>_distribution
whereT
is some numeric types depending onvalue_type
- Returns a single random number within [current, end)
- Fill
container
with random numbers within [current, end) - Fill
container
withcount
random numbers within [current, end), equivalent to:fillRand(std::begin(container), std::begin(container) + count)
- Fill the range pointed by the iterators [begin, end) with random numbers within [current, end)
- 5-8 uses
rand()
from<stdlib>
, which have the same usage as 1-4
friend std::ostream& operator<<(std::ostream& os, Range const& range);
Print range in the format of: [current,end]