diff options
Diffstat (limited to 'test/test_utils.hpp')
-rw-r--r-- | test/test_utils.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/test_utils.hpp b/test/test_utils.hpp index acee5d0..a695134 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -66,4 +66,19 @@ rand_between(Context& ctx, const size_t min, const size_t max) return r; } +/// Return an array of D precisions with sum at most N and each at most Max +template <size_t N, size_t D, size_t Max = 64> +std::array<size_t, D> +make_random_precisions(Context& ctx) +{ + std::array<size_t, D> ms; + size_t bits_left = N; + for (size_t i = 0; i < D; ++i) { + ms[i] = rand_between(ctx, 1, std::min(Max, bits_left / (D - i) + 1)); + bits_left -= ms[i]; + } + + return ms; +} + #endif |