first commit

This commit is contained in:
2026-02-08 15:20:10 -05:00
parent a29d42f93a
commit 89eab3da05
9 changed files with 366 additions and 3 deletions
+24
View File
@@ -0,0 +1,24 @@
package utilities
import (
"math"
"math/rand/v2"
"time"
)
var (
ApplyJitter = DefaultApplyJitter
)
func DefaultApplyJitter(pauseDuration time.Duration, jitter time.Duration) time.Duration {
switch {
case jitter == 0, pauseDuration == 0:
return pauseDuration
case jitter > pauseDuration:
pauseDuration, jitter = jitter, pauseDuration
}
min := pauseDuration.Nanoseconds() - jitter.Nanoseconds()
max := pauseDuration.Nanoseconds() + jitter.Nanoseconds()
rnd := int64(math.Max(float64(rand.Int64N(max-min)+min), 0))
return time.Duration(rnd)
}
+8
View File
@@ -0,0 +1,8 @@
package utilities
import "math/big"
func ProductWouldOverflowInt64(a, b int64) (product int64, overflows bool) {
results := new(big.Int).Mul(big.NewInt(a), big.NewInt(b))
return results.Int64(), !results.IsInt64()
}