Data Science, Computer Science, Python, Probability, Machine Learning.
right border that is greater or equal to the sampled value. Again, a simple helper function for doing exactly this: func FindIndexFromRight(val float64, cdf []float64) int { for i, cumProb := range cdf { if cumProb >= val { return i } } return len(cdf) - 1 } Putting everything together With that,