2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-01-20 17:52:24 +00:00
|
|
|
|
|
|
|
package tstime
|
|
|
|
|
|
|
|
import (
|
2024-06-05 22:37:31 +01:00
|
|
|
"math/rand/v2"
|
2021-01-20 17:52:24 +00:00
|
|
|
"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
|
|
|
|
}
|
2024-06-05 22:37:31 +01:00
|
|
|
return min + rand.N(max-min)
|
2021-01-20 17:52:24 +00:00
|
|
|
}
|