From eda98d82e679a57c94a0ee8aa0bc4ce2ded561d9 Mon Sep 17 00:00:00 2001 From: sunbin Date: Wed, 22 Jan 2025 10:32:36 +0800 Subject: [PATCH 1/4] Fix: UniformIntGenerator range error --- cpp/open3d/utility/Random.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/open3d/utility/Random.h b/cpp/open3d/utility/Random.h index ffb5a4113a3..5a7f14d9d40 100644 --- a/cpp/open3d/utility/Random.h +++ b/cpp/open3d/utility/Random.h @@ -68,7 +68,7 @@ class UniformIntGenerator { /// /// \param low The lower bound (inclusive). /// \param high The upper bound (exclusive). \p high must be > \p low. - UniformIntGenerator(const T low, const T high) : distribution_(low, high) { + UniformIntGenerator(const T low, const T high) : distribution_(low, high-1) { if (low < 0) { utility::LogError("low must be > 0, but got {}.", low); } From c5a0f6bde3b437d3c32c5a129fb40a5fad89a098 Mon Sep 17 00:00:00 2001 From: sunbin Date: Wed, 22 Jan 2025 13:44:28 +0800 Subject: [PATCH 2/4] Fix the UniformIntGenerator function description --- cpp/open3d/utility/Random.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/open3d/utility/Random.h b/cpp/open3d/utility/Random.h index 5a7f14d9d40..21d022e7ead 100644 --- a/cpp/open3d/utility/Random.h +++ b/cpp/open3d/utility/Random.h @@ -43,7 +43,7 @@ std::mutex* GetMutex(); /// This function is automatically protected by the global random mutex. uint32_t RandUint32(); -/// Generate uniformly distributed random integers in [low, high). +/// Generate uniformly distributed random integers in [low, high]. /// This class is globally seeded by utility::random::Seed(). /// This class is a wrapper around std::uniform_int_distribution. /// @@ -54,7 +54,7 @@ uint32_t RandUint32(); /// // Globally seed Open3D. This will affect all random functions. /// utility::random::Seed(0); /// -/// // Generate a random int in [0, 100). +/// // Generate a random int in [0, 100]. /// utility::random::UniformIntGenerator gen(0, 100); /// for (size_t i = 0; i < 10; i++) { /// std::cout << gen() << std::endl; @@ -64,11 +64,11 @@ template class UniformIntGenerator { public: /// Generate uniformly distributed random integer from - /// [low, low + 1, ... high - 1]. + /// [low, low + 1, ... high]. /// /// \param low The lower bound (inclusive). /// \param high The upper bound (exclusive). \p high must be > \p low. - UniformIntGenerator(const T low, const T high) : distribution_(low, high-1) { + UniformIntGenerator(const T low, const T high) : distribution_(low, high) { if (low < 0) { utility::LogError("low must be > 0, but got {}.", low); } From 42f71fb4f5dd869781526640c6ced11a074d13f5 Mon Sep 17 00:00:00 2001 From: sunbin Date: Thu, 23 Jan 2025 16:45:47 +0800 Subject: [PATCH 3/4] Fix: change the validation check conform to std::uniform_int_distribution --- cpp/open3d/utility/Random.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/open3d/utility/Random.h b/cpp/open3d/utility/Random.h index 21d022e7ead..e7c6e928971 100644 --- a/cpp/open3d/utility/Random.h +++ b/cpp/open3d/utility/Random.h @@ -67,13 +67,13 @@ class UniformIntGenerator { /// [low, low + 1, ... high]. /// /// \param low The lower bound (inclusive). - /// \param high The upper bound (exclusive). \p high must be > \p low. + /// \param high The upper bound (inclusive). \p high must be >= \p low. UniformIntGenerator(const T low, const T high) : distribution_(low, high) { if (low < 0) { utility::LogError("low must be > 0, but got {}.", low); } - if (low >= high) { - utility::LogError("low must be < high, but got low={} and high={}.", + if (low > high) { + utility::LogError("low must be <= high, but got low={} and high={}.", low, high); } } From 9cf1d1c5c9467488ddd8280ae1aa9bc2c59b4f89 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Wed, 29 Jan 2025 06:34:24 -0800 Subject: [PATCH 4/4] apply style --- cpp/open3d/utility/Random.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/open3d/utility/Random.h b/cpp/open3d/utility/Random.h index e7c6e928971..46566a2128c 100644 --- a/cpp/open3d/utility/Random.h +++ b/cpp/open3d/utility/Random.h @@ -73,8 +73,9 @@ class UniformIntGenerator { utility::LogError("low must be > 0, but got {}.", low); } if (low > high) { - utility::LogError("low must be <= high, but got low={} and high={}.", - low, high); + utility::LogError( + "low must be <= high, but got low={} and high={}.", low, + high); } }