File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ export namespace CppUtils::Math
77 template<std::integral Integer>
88 inline auto getRandomNumberInInterval(Integer min, Integer max) -> Integer
99 {
10- static auto randomDevice = std::random_device{};
11- static auto engine = std::mt19937{randomDevice()};
10+ thread_local auto engine = [] {
11+ static auto randomDevice = std::random_device{};
12+ return std::mt19937{randomDevice() ^ std::hash<std::thread::id>{}(std::this_thread::get_id())};
13+ }();
1214 auto distribution = std::uniform_int_distribution<Integer>{min, max};
1315 auto randomNumber = distribution(engine);
1416 return randomNumber;
Original file line number Diff line number Diff line change @@ -43,11 +43,6 @@ export namespace CppUtils::Math
4343 static_assert(not isEqual(0.1 + 0.2, 0.29));
4444 static_assert(not isEqual(0.1 + 0.2, 0.31));
4545
46- [[nodiscard]] inline constexpr auto roundToNDecimals(std::floating_point auto number, std::size_t nbDecimals) -> decltype(number)
47- {
48- return std::round(number * static_cast<decltype(number)>(nbDecimals)) / static_cast<decltype(number)>(nbDecimals);
49- }
50-
5146 [[nodiscard]] inline constexpr auto isBetween(auto value, auto low, auto high) noexcept -> bool
5247 {
5348 return low <= value and value <= high;
Original file line number Diff line number Diff line change @@ -393,8 +393,8 @@ export namespace CppUtils::Network
393393 template<>
394394 [[nodiscard]] inline auto receive<std::vector<std::byte>>(std::size_t bufferSize) -> std::optional<std::vector<std::byte>>
395395 {
396- auto buffer = std::vector<std::byte>{bufferSize };
397- buffer.reserve (bufferSize);
396+ auto buffer = std::vector<std::byte>{};
397+ buffer.resize (bufferSize);
398398 for (auto totalBytesReceived = 0uz; totalBytesReceived < bufferSize;)
399399 {
400400#if defined(OS_WINDOWS)
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ export namespace CppUtils::UnitTest::Thread::Scheduler
189189
190190 suite.addTest("Stress test with many tasks", [&] {
191191 auto scheduler = CppUtils::Thread::Scheduler{};
192- const auto numTasks = 100 '000uz;
192+ const auto numTasks = 10 '000uz;
193193 auto executedCount = std::atomic_size_t{0};
194194
195195 for (auto i = 0uz; i < numTasks; ++i)
You can’t perform that action at this time.
0 commit comments