INNER CODE UNIT · Go

RandomTimeInRange

asobti/kube-monkey · internal/pkg/calendar/calendar.go:106

func RandomTimeInRange(startHour int, endHour int, loc *time.Location) (time.Time, bool) {
	return randomTimeInRange(time.Now(), newRand(), startHour, endHour, loc)
}

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)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…