BalanceAction pickRandomRegions(BalancerClusterState cluster, int thisServer, int otherServer) {
    if (thisServer < 0 || otherServer < 0) {
      return BalanceAction.NULL_ACTION;
    }

    // Decide who is most likely to need another region
    int thisRegionCount = cluster.getNumRegions(thisServer);
    int otherRegionCount = cluster.getNumRegions(otherServer);

    // Assign the chance based upon the above
    double thisChance = (thisRegionCount > otherRegionCount) ? 0 : 0.5;
    double otherChance = (thisRegionCount <= otherRegionCount) ? 0 : 0.5;

    int thisRegion = pickRandomRegion(cluster, thisServer, thisChance);
    int otherRegion = pickRandomRegion(cluster, otherServer, otherChance);

    return getAction(thisServer, thisRegion, otherServer, otherRegion);
  }
From a list of regions pick a random one. Null can be returned which
{@link StochasticLoadBalancer#balanceCluster(Map)} recognize as signal to try a region move
rather than swap.
@param cluster        The state of the cluster
@param server         index of the server
@param chanceOfNoSwap Chance that this will decide to try a move rather than a swap.
@return a random {@link RegionInfo} or null if an asymmetrical move is suggested.
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CandidateGenerator.java