From 9577d5bc1a9c91a54d390fe888ee56d393e91417 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 27 Jul 2023 18:02:16 +0200 Subject: A3: Concurrency exercise.. --- a3/concurrency.cc | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'a3/concurrency.cc') diff --git a/a3/concurrency.cc b/a3/concurrency.cc index da7b51e..9838212 100644 --- a/a3/concurrency.cc +++ b/a3/concurrency.cc @@ -41,6 +41,47 @@ void measure(const std::string& text, Callable c) } } +template +std::vector get_random_vector(std::size_t size, + T min = std::numeric_limits::min(), + T max = std::numeric_limits::max()) +{ + std::default_random_engine generator; + // Randomly generate T-values from the range [min; max] + std::uniform_int_distribution distrib(min, max); + + std::vector v; + v.resize(size); + for(auto& item : v) + { + item = distrib(generator); + } + + return v; +} + +std::vector get_random_strings(std::size_t size, + std::size_t length, + char min, char max) +{ + std::default_random_engine generator; + // Randomly generate T-values from the range [min; max] + std::uniform_int_distribution distrib(min, max); + + std::vector v; + v.resize(size); + for(auto& str : v) + { + str.reserve(length); + for(auto i = 0u; i < str.capacity(); ++i) + { + str += distrib(generator); + } + } + + return v; +} + template // requires std::forward_iterator requires std:: ranges::input_range @@ -116,47 +157,6 @@ std::vector find_all(const C& v, const T& key, std::size_t n) return res; } -template -std::vector get_random_vector(std::size_t size, - T min = std::numeric_limits::min(), - T max = std::numeric_limits::max()) -{ - std::default_random_engine generator; - // Randomly generate T-values from the range [min; max] - std::uniform_int_distribution distrib(min, max); - - std::vector v; - v.resize(size); - for(auto& item : v) - { - item = distrib(generator); - } - - return v; -} - -std::vector get_random_strings(std::size_t size, - std::size_t length, - char min, char max) -{ - std::default_random_engine generator; - // Randomly generate T-values from the range [min; max] - std::uniform_int_distribution distrib(min, max); - - std::vector v; - v.resize(size); - for(auto& str : v) - { - str.reserve(length); - for(auto i = 0u; i < str.capacity(); ++i) - { - str += distrib(generator); - } - } - - return v; -} - int main() { { -- cgit v1.2.3