def sample()

in cassovary-core/src/main/scala/com/twitter/cassovary/util/BinomialDistribution.scala [32:41]


  def sample(rng: Random): Int = p match {
    case 1 => n
    case 0 => 0
    case _ =>
      val unifDouble = rng.nextDouble()
      Arrays.binarySearch(cdf, unifDouble) match {
        case found: Int if found >= 0 => found - 1
        case negatedInsertionPointMinusOne: Int => -negatedInsertionPointMinusOne - 1
      }
  }