You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2023/01/11 03:35:28 UTC

[GitHub] [hbase] Apache9 commented on a diff in pull request #4954: HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection

Apache9 commented on code in PR #4954:
URL: https://github.com/apache/hbase/pull/4954#discussion_r1066543958


##########
hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java:
##########
@@ -116,13 +116,13 @@ public static <T> T selectWeightedRandomItem(List<Pair<T, Integer>> items) {
 
   /** Selects and returns ceil(ratio * items.length) random items from the given array */
   public static <T> List<T> selectRandomItems(T[] items, float ratio) {
-    int selectedNumber = (int) Math.ceil(items.length * ratio);
-
-    List<T> originalItems = Arrays.asList(items);
+    final int selectedNumber = (int) Math.ceil(items.length * ratio);
+    final List<T> originalItems = Arrays.asList(items);
     Collections.shuffle(originalItems);
-
-    int startIndex = ThreadLocalRandom.current().nextInt(items.length - selectedNumber);
-    return originalItems.subList(startIndex, startIndex + selectedNumber);
+    final int startIndex =

Review Comment:
   So the problem here is ratio could be greater than 1.0?



-- 
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: issues-unsubscribe@hbase.apache.org

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