Skip to content

Commit 9bc173c

Browse files
authored
fix(autoware_universe_utils): fix bug in test (#9710)
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
1 parent 8949358 commit 9bc173c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

common/autoware_universe_utils/test/src/math/test_trigonometry.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <gtest/gtest.h>
1919

2020
#include <cmath>
21+
#include <random>
2122

2223
TEST(trigonometry, sin)
2324
{
@@ -60,11 +61,15 @@ float normalize_angle(double angle)
6061

6162
TEST(trigonometry, opencv_fast_atan2)
6263
{
64+
std::random_device rd;
65+
std::mt19937 gen(rd());
66+
67+
// Generate random x and y between -10.0 and 10.0 as float
68+
std::uniform_real_distribution<float> dis(-10.0f, 10.0f);
69+
6370
for (int i = 0; i < 100; ++i) {
64-
// Generate random x and y between -10 and 10
65-
std::srand(0);
66-
float x = static_cast<float>(std::rand()) / RAND_MAX * 20.0 - 10.0;
67-
float y = static_cast<float>(std::rand()) / RAND_MAX * 20.0 - 10.0;
71+
const float x = dis(gen);
72+
const float y = dis(gen);
6873

6974
float fast_atan = autoware::universe_utils::opencv_fast_atan2(y, x);
7075
float std_atan = normalize_angle(std::atan2(y, x));

0 commit comments

Comments
 (0)