summaryrefslogtreecommitdiffhomepage
path: root/tstime/jitter.go
blob: 987680f3c0ba778843be762c56cf0820a4ff483b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause

package tstime

import (
	"math/rand/v2"
	"time"
)

// RandomDurationBetween returns a random duration in range [min,max).
// If panics if max < min.
func RandomDurationBetween(min, max time.Duration) time.Duration {
	diff := max - min
	if diff == 0 {
		return min
	}
	return min + rand.N(max-min)
}