public static <T> T selectWeightedRandomItem(List<Pair<T, Integer>> items) {
    int totalWeight = 0;
    for (Pair<T, Integer> pair : items) {
      totalWeight += pair.getSecond();
    }

    int cutoff = ThreadLocalRandom.current().nextInt(totalWeight);
    int cummulative = 0;
    T item = null;

    // warn: O(n)
    for (int i = 0; i < items.size(); i++) {
      int curWeight = items.get(i).getSecond();
      if (cutoff < cummulative + curWeight) {
        item = items.get(i).getFirst();
        break;
      }
      cummulative += curWeight;
    }

    return item;
  }
Selects a random item from the given items with weights
hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java