#pragma once #include #include #include #include namespace fuzzer { class random_generator { public: random_generator(); void fill(std::span data); void fill(void* data, size_t size); template requires(std::is_trivially_copyable_v) T get() { T value{}; this->fill(&value, sizeof(value)); return value; } template T get(const T& max) { return this->get() % max; } template T get(T min, T max) { if (max < min) { std::swap(max, min); } const auto diff = max - min; return (this->get() % diff) + min; } template T get_geometric() { T value{0}; while (this->get()) { ++value; } return value; } private: std::mt19937 rng_; std::uniform_int_distribution distribution_{}; std::mt19937::result_type generate_number(); }; template <> inline bool random_generator::get() { return (this->generate_number() & 1) != 0; } }