code: function sampleSizeFraction(num, total, withReplacement) {
    const minSamplingRate = 1e-10;        // Limited by RNG's resolution
    const delta = 1e-4;                   // To have 0.9999 success rate
    const fraction = num / total;
    let upperBound;
  
    if (withReplacement) {
      // Poisson upper bound for Pr(num successful poisson trials) > (1-delta)
      let numStd = num < 6 ? 12 : num < 16 ? 9 : 6;
      upperBound = Math.max(num + numStd * Math.sqrt(num), minSamplingRate) / total;
    } else {
      // Binomial upper bound for Pr(num successful bernoulli trials) > (1-delta)
      let gamma = - Math.log(delta) / total;
      upperBound = Math.min(1, Math.max(minSamplingRate, fraction + gamma + Math.sqrt(gamma * gamma + 2 * gamma * fraction)));
    }
    return upperBound;
  }
docs: Returns a sampling rate that ensures a size >= lowerBound most of the time. Inspired from spark