code: public String chooseRack(Set<String> excludedRacks) {
      String chosenRack = null;
      HashSet<Integer> chosenIndexes = new HashSet<Integer>();
  
      netlock.readLock().lock();
      try {
        int totalRacks = getNumOfRacks();
        if (totalRacks - excludedRacks.size() <= 0)
          return null; // all racks are excluded
  
        while (true) {
          int rackIndex;
          do {
            rackIndex = r.nextInt(totalRacks);
          } while (chosenIndexes.contains(rackIndex));
          
          chosenIndexes.add(rackIndex);
          chosenRack = racks.get(rackIndex);
          
          // if no excluded nodes are specified or the chosen node is not excluded
          // return it
          if (excludedRacks == null || (!excludedRacks.contains(chosenRack))) {
            return chosenRack;
          }
          // for sanity check if we used all indexes
          if (chosenIndexes.size() == totalRacks) {
            return null;
          }
        }
      } finally {
        netlock.readLock().unlock();
      }
    }
docs: Choose a rack which is not in exlcudedRacks
  @param excludedRacks excluded racks
  @return a rack