code: private static boolean addIsotopeDist(IMolecularFormula mf,
                                            IIsotope[] isotopes,
                                            int idx, int count) {
          if (count == 0)
              return true;
          double frac = 100d;
          for (int i = 0; i < idx; i++)
              frac -= isotopes[i].getNaturalAbundance();
          double p = isotopes[idx].getNaturalAbundance() / frac;
  
          if (p >= 1.0) {
              mf.addIsotope(isotopes[idx], count);
              return true;
          }
  
          double kMin = (count + 1) * (1 - p) - 1;
          double kMax = (count + 1) * (1 - p);
          if ((int) Math.ceil(kMin) == (int) Math.floor(kMax)) {
              int k = (int) kMax;
              mf.addIsotope(isotopes[idx], count - k);
              // recurse with remaining
              return addIsotopeDist(mf, isotopes, idx + 1, k);
          }
          return false; // multiple are most abundant
      }
docs: Helper method for adding isotope distributions to a MF. The method adds
  a distribution of isotopes by splitting the set of isotopes in two,
  the one under consideration (specified by 'idx') and the remaining to be
  considered ('&gt;idx'). The inflection point is calculate as 'k'
  &le 'count' isotopes added. If there are remaining isotopes the method
  calls it's self with 'idx+1' and 'count := k'.
  
  @param mf       the molecular formula to update
  @param isotopes the isotopes, sorted most abundance to least
  @param idx      which isotope we're currently considering
  @param count    the number of isotopes remaining to select from
  @return the distribution is unique (or not)