A bunch of functions so you don't have to write them. The main purpose of the repo is to unify the most used tools and make them deterministic to the random seed.
git clone https://github.com/establishment/generator-utils
cd generator-utils
make install- All functions which take a range as parameter generate values in
[left, right). Adding axin front of these functions makes the generated values[left, right]. For example,Range(2)returns a vector with[0, 1]while xRange(2) returns[0, 1, 2]. - Nothing throws exceptions, just
assert(0)for now
- Returns a vector with
[left, left + step, .. right)Other versionsRange(left, right),Range(right)and all of these withx
- Applies basic stl function directly on containers(
vectors)
Actual signature Container<Type>& Sort(Container<Type>&) Container<Type>&& Sort(Container<Type>&&) - for function call return values
vector<int> x = {1, 3, 2, 2, 3, 1, 1, 5};
Reverse(Unique(x)); // Unique sorts as well, because you want that
// x will be {5, 3, 2, 1}
auto v = Sort(FunctionThatReturnsAVector());
- Returns a vector of
num_elementsnumbers in range[left, right)Other versionsUniqueNumbers(right, num_elements)- all version work withxas well
Honorable mentions UniqueNumbers(left, right, num_elements, const std::function<bool(Type)>& valid_number) - returns random numbers, but only numbers for which the function returns true
- Returns a vector of
num_bucketselements. The sum of the elements isnum_elementsand each of them is>= min_val. Assuming thatmin_val = 0, the returned partition is a random, each possible valid partition having the same chance to be chosen.
- Returns a random number in [left, right). The weight of the number depends on the function
- All
Randfunctions have a x version, for which the retured value will be in [left, right].
Rand(left, right)
- Basic rand in interval [left, right)
Other versions
Rand()Rand(right)
RandLog(left, right)
- Give a random value in [left, right), value x having the weight equal to 1/x
RandLogScaled(left, right)
- same as
RandLogbut elementihas weight equal to1 / (i - left + 1)