first commit
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user