code: private int randomWithRankedValues(IntVar x) {
          TIntArrayList[] values = new TIntArrayList[ranks.length];
  
          DisposableValueIterator ite = x.getValueIterator(true);
          try {
              while (ite.hasNext()) {
                  int v = ite.next();
                  int i;
  
                  for (i = 0; i < ranks.length; i++) {
                      if (ranks[i].contains(v)) {
                          if (values[i] == null) {
                              values[i] = new TIntArrayList();
                          }
                          values[i].add(v);
                      }
                  }
              }
          } finally {
              ite.dispose();
          }
  
          //We pick a random value in the first rank that is not empty (aka null here)
          for (TIntArrayList rank : values) {
              if (rank != null) {
                  int v = rnd.nextInt(rank.size());
                  return rank.get(v);
              }
          }
          return -1;
      }
docs: Random value but that consider the rank of nodes.
  So values are picked up from the first rank possible.