From e6ce15d4221f3f8dc9af0913467b7230ee552d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Thu, 12 Jun 2025 11:24:46 +0300 Subject: [PATCH] =?UTF-8?q?TASK00=20-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=BC=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=87=D0=B8=D1=81=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/helpers.cpp | 10 ++++++++++ src/helpers/helpers.h | 2 ++ tests/helpers/helpers_TEST.cpp | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/helpers/helpers.cpp b/src/helpers/helpers.cpp index 71605c6..8562faf 100644 --- a/src/helpers/helpers.cpp +++ b/src/helpers/helpers.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -115,4 +116,13 @@ std::string ToHex(std::byte* src, size_t len) return ret; } + +uint64_t Random() +{ + std::random_device device; + std::mt19937 random_generator(device()); + std::uniform_int_distribution dist(0,UINT64_MAX); + + return dist(random_generator); +} } // namespace uad diff --git a/src/helpers/helpers.h b/src/helpers/helpers.h index d214a65..318f47f 100644 --- a/src/helpers/helpers.h +++ b/src/helpers/helpers.h @@ -11,4 +11,6 @@ std::string PathCat(boost::beast::string_view base, boost::beast::string_view pa void Fail(boost::beast::error_code ec, char const* what); std::string ToHex(std::byte* src, size_t len); + +uint64_t Random(); } // namespace uad diff --git a/tests/helpers/helpers_TEST.cpp b/tests/helpers/helpers_TEST.cpp index 1ec939b..9fc0391 100644 --- a/tests/helpers/helpers_TEST.cpp +++ b/tests/helpers/helpers_TEST.cpp @@ -52,3 +52,39 @@ BOOST_AUTO_TEST_CASE(ToHex_should_return_empty_string_if_no_arr_or_no_length) BOOST_CHECK_EQUAL(ToHex(&a1, 0), ""s); BOOST_CHECK_EQUAL(ToHex(nullptr, 1), ""s); } + +BOOST_AUTO_TEST_CASE(Random_should_return_different_numbers_on_multiple_calls) +{ + auto a1 = Random(); + auto a2 = Random(); + auto a3 = Random(); + auto a4 = Random(); + auto a5 = Random(); + auto a6 = Random(); + auto a7 = Random(); + auto a8 = Random(); + auto a9 = Random(); + auto a10 = Random(); + + auto b1 = Random(); + auto b2 = Random(); + auto b3 = Random(); + auto b4 = Random(); + auto b5 = Random(); + auto b6 = Random(); + auto b7 = Random(); + auto b8 = Random(); + auto b9 = Random(); + auto b10 = Random(); + + BOOST_CHECK(a1 != b1); + BOOST_CHECK(a2 != b2); + BOOST_CHECK(a3 != b3); + BOOST_CHECK(a4 != b4); + BOOST_CHECK(a5 != b5); + BOOST_CHECK(a6 != b6); + BOOST_CHECK(a7 != b7); + BOOST_CHECK(a8 != b8); + BOOST_CHECK(a9 != b9); + BOOST_CHECK(a10 != b10); +}