You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/06/21 14:42:45 UTC

[GitHub] [geode-native] gaussianrecurrence commented on a diff in pull request #974: GEODE-10371: C++ client: Improve dispersion on connections expiration

gaussianrecurrence commented on code in PR #974:
URL: https://github.com/apache/geode-native/pull/974#discussion_r902712371


##########
cppcache/src/TcrConnection.cpp:
##########
@@ -63,23 +63,10 @@ bool useReplyTimeout(const apache::geode::client::TcrMessage& request) {
 }
 
 int expiryTimeVariancePercentage() {
-  auto nowTimePoint = std::chrono::steady_clock::now().time_since_epoch();
-  auto now_ms =
-      std::chrono::duration_cast<std::chrono::milliseconds>(nowTimePoint)
-          .count();
-  auto now_s =
-      std::chrono::duration_cast<std::chrono::seconds>(nowTimePoint).count();
-
-  srand(static_cast<unsigned int>((now_s * 1000) + (now_ms / 1000)));
-
-  const int numbers = 21;
-  // NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.rand): TODO replace
-  int random = rand() % numbers + 1;
-
-  if (random > 10) {
-    random = random - numbers;
-  }
-  return random;
+  std::random_device rd;
+  std::default_random_engine generator(rd());
+  std::uniform_int_distribution<int> distribution(-9, 9);

Review Comment:
   It'd be good to add a couple of constants to add some semantic meaning to the distribution limits



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org