diff --git a/modules/gapi/test/common/gapi_parsers_tests_common.hpp b/modules/gapi/test/common/gapi_parsers_tests_common.hpp index 91dcca7b3e..328f86b851 100644 --- a/modules/gapi/test/common/gapi_parsers_tests_common.hpp +++ b/modules/gapi/test/common/gapi_parsers_tests_common.hpp @@ -176,7 +176,7 @@ private: int randInRange(const int start, const int end) { GAPI_Assert(start <= end); - return start + std::rand() % (end - start + 1); + return theRNG().uniform(start, end); } cv::Rect generateBox(const cv::Size& in_sz) @@ -211,7 +211,7 @@ private: SSDitem it; it.image_id = static_cast(i); it.label = static_cast(randInRange(0, 9)); - it.confidence = static_cast(std::rand()) / RAND_MAX; + it.confidence = theRNG().uniform(0.f, 1.f); auto box = generateBox(in_sz); it.rc_left = normalize(box.x, in_sz.width); it.rc_right = normalize(box.x + box.width, in_sz.width); @@ -245,9 +245,10 @@ public: auto data = mat.ptr(); const size_t range = std::accumulate(dims.begin(), dims.end(), 1, std::multiplies()); + cv::RNG& rng = theRNG(); for (size_t i = 0; i < range; ++i) { - data[i] = static_cast(std::rand()) / RAND_MAX; + data[i] = rng.uniform(0.f, 1.f); } return mat; } diff --git a/modules/gapi/test/rmat/rmat_tests.cpp b/modules/gapi/test/rmat/rmat_tests.cpp index 9980925a3b..52c3806c5b 100644 --- a/modules/gapi/test/rmat/rmat_tests.cpp +++ b/modules/gapi/test/rmat/rmat_tests.cpp @@ -116,11 +116,11 @@ public: // we have some specific data hidden under RMat, // test that we can obtain it via RMat.as() method TEST(RMat, UsageInBackend) { - int i = std::rand(); + int i = 123456; auto rmat = cv::make_rmat(i); auto adapter = rmat.get(); - EXPECT_NE(nullptr, adapter); + ASSERT_NE(nullptr, adapter); EXPECT_EQ(i, adapter->deviceSpecificData()); } } // namespace opencv_test diff --git a/modules/gapi/test/test_precomp.hpp b/modules/gapi/test/test_precomp.hpp index 6253acfcb3..7b3c695443 100644 --- a/modules/gapi/test/test_precomp.hpp +++ b/modules/gapi/test/test_precomp.hpp @@ -34,4 +34,7 @@ static inline void countNonZero_is_forbidden_in_tests_use_norm_instead() {} } #define countNonZero() countNonZero_is_forbidden_in_tests_use_norm_instead() +#undef RAND_MAX +#define RAND_MAX RAND_MAX_is_banned_in_tests__use_cv_theRNG_instead + #endif // __OPENCV_GAPI_TEST_PRECOMP_HPP__