mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
datagen.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "util/GridSearch.hpp"
4#include <random>
5#include <type_traits>
6#include <utility>
7
8
9namespace m {
10
12namespace datagen {
13
16template<typename T, typename Generator = std::mt19937_64>
17std::vector<T> generate_uniform_distinct_numbers(const T min, const T max, const std::size_t count,
18 Generator &&g = Generator())
19{
20 static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type");
21 M_insist(min <= max);
22 M_insist(is_range_wide_enough<T>(min, max, count), "range [min, max] does not have count distinct values");
23
24 if (count == 1) return std::vector<T>(1, min);
25 std::vector<T> values = gs::LinearSpace<T>(min, max, count-1).sequence();
26
27 std::shuffle(values.begin(), values.end(), std::forward<Generator>(g));
28
29 return values;
30}
31
32}
33
34}
#define M_insist(...)
Definition: macro.hpp:129
std::vector< T > generate_uniform_distinct_numbers(const T min, const T max, const std::size_t count, Generator &&g=Generator())
Generate count many distinct numbers of type T, chosen uniformly at random from the range [min,...
Definition: datagen.hpp:17
‍mutable namespace
Definition: Backend.hpp:10
std::vector< value_type > sequence() const
Definition: GridSearch.hpp:114