INNER CODE UNIT · Go
killTimesInRange
asobti/kube-monkey · internal/pkg/calendar/calendar.go:110
func killTimesInRange(now time.Time, r *rand.Rand, mtbf time.Duration, startHour int, endHour int, loc *time.Location) []time.Time {
start, remaining, full := rangeToday(now, startHour, endHour, loc)
if remaining == 0 || mtbf <= 0 {
return nil
}
// Kills are spread over the day but only ever happen inside the range, so
// the share of the range still ahead of us is the share of the day's kills
// left to schedule.
expected := (float64(24*time.Hour) / float64(mtbf)) * (float64(remaining) / float64(full))
// The whole part is a kill we owe for sure, the fraction left over is the
// chance of one more.
count := int(expected)
if r.Float64() < expected-float64(count) {
count++
}