From aec9aad119cc7c3bd9c34ea4def4cffde90ba52f Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Fri, 22 Apr 2022 08:29:11 +0200 Subject: [PATCH] [T] Fill std::array randomly --- Tests/VectorUtils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/VectorUtils.h b/Tests/VectorUtils.h index a8548415588..78cba91f96f 100644 --- a/Tests/VectorUtils.h +++ b/Tests/VectorUtils.h @@ -42,3 +42,16 @@ inline void fillVectorRandomly(std::vector<double>& x) value = rnd(random_number_generator); } } + +template <std::size_t N> +void fillVectorRandomly(std::array<double, N>& x) +{ + std::random_device rd; + std::mt19937 random_number_generator(rd()); + std::uniform_real_distribution<double> rnd; + + for (auto& value : x) + { + value = rnd(random_number_generator); + } +} -- GitLab