diff --git a/certificate/renewal.go b/certificate/renewal.go index f85781e90..83268aa05 100644 --- a/certificate/renewal.go +++ b/certificate/renewal.go @@ -4,7 +4,7 @@ import ( "context" "crypto/x509" "fmt" - "math/rand" + "math/rand/v2" "time" "github.com/go-acme/lego/v5/acme" @@ -31,7 +31,7 @@ func (r *RenewalInfo) ShouldRenewAt(now time.Time, willingToSleep time.Duration) // Select a uniform random time within the suggested window. rt := start if window := end.Sub(start); window > 0 { - randomDuration := time.Duration(rand.Int63n(int64(window))) + randomDuration := time.Duration(rand.Int64N(int64(window))) rt = rt.Add(randomDuration) } diff --git a/cmd/cmd_renew.go b/cmd/cmd_renew.go index 6fbf9454a..e891d019f 100644 --- a/cmd/cmd_renew.go +++ b/cmd/cmd_renew.go @@ -7,7 +7,7 @@ import ( "fmt" "log/slog" "math" - "math/rand" + "math/rand/v2" "os" "slices" "sort" @@ -391,8 +391,7 @@ func randomSleep(cmd *cli.Command) { // https://github.com/certbot/certbot/blob/284023a1b7672be2bd4018dd7623b3b92197d4b0/certbot/certbot/_internal/renewal.py#L472 const jitter = 8 * time.Minute - rnd := rand.New(rand.NewSource(time.Now().UnixNano())) - sleepTime := time.Duration(rnd.Int63n(int64(jitter))) + sleepTime := time.Duration(rand.Int64N(int64(jitter))) log.Info("renewal: random delay.", slog.Duration("sleep", sleepTime)) time.Sleep(sleepTime) diff --git a/providers/dns/lightsail/lightsail.go b/providers/dns/lightsail/lightsail.go index 8cc92afc1..c88cb651a 100644 --- a/providers/dns/lightsail/lightsail.go +++ b/providers/dns/lightsail/lightsail.go @@ -5,7 +5,7 @@ import ( "context" "errors" "fmt" - "math/rand" + "math/rand/v2" "strconv" "time" @@ -98,7 +98,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { options.Backoff = retry.BackoffDelayerFunc(func(attempt int, err error) (time.Duration, error) { retryCount := min(attempt, 7) - delay := (1 << uint(retryCount)) * (rand.Intn(50) + 200) + delay := (1 << uint(retryCount)) * (rand.IntN(50) + 200) return time.Duration(delay) * time.Millisecond, nil }) diff --git a/providers/dns/liquidweb/servermock_test.go b/providers/dns/liquidweb/servermock_test.go index 24b4a6cd0..98d051af6 100644 --- a/providers/dns/liquidweb/servermock_test.go +++ b/providers/dns/liquidweb/servermock_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "io" - "math/rand" + "math/rand/v2" "net/http" "net/http/httptest" "testing" @@ -63,7 +63,7 @@ func mockAPICreate(recs map[int]network.DNSRecord) http.HandlerFunc { return } - payload.Params.ID = types.FlexInt(rand.Intn(10000000)) + payload.Params.ID = types.FlexInt(rand.IntN(10000000)) payload.Params.ZoneID = types.FlexInt(mockAPIServerZones[payload.Params.Name]) if _, exists := recs[int(payload.Params.ID)]; exists { diff --git a/providers/dns/nearlyfreespeech/internal/client.go b/providers/dns/nearlyfreespeech/internal/client.go index aedb566be..41d55a0f8 100644 --- a/providers/dns/nearlyfreespeech/internal/client.go +++ b/providers/dns/nearlyfreespeech/internal/client.go @@ -6,7 +6,7 @@ import ( "encoding/json" "fmt" "io" - "math/rand" + "math/rand/v2" "net/http" "net/url" "strconv" @@ -136,7 +136,7 @@ func getRandomSalt() []byte { // This is the only part of this that needs to be serialized. salt := make([]byte, 16) for i := range 16 { - salt[i] = saltBytes[rand.Intn(len(saltBytes))] + salt[i] = saltBytes[rand.IntN(len(saltBytes))] } return salt diff --git a/providers/dns/route53/route53.go b/providers/dns/route53/route53.go index 4d624adf2..42fd5fa81 100644 --- a/providers/dns/route53/route53.go +++ b/providers/dns/route53/route53.go @@ -5,7 +5,7 @@ import ( "context" "errors" "fmt" - "math/rand" + "math/rand/v2" "strings" "time" @@ -354,7 +354,7 @@ func createAWSConfig(ctx context.Context, config *Config) (aws.Config, error) { options.Backoff = retry.BackoffDelayerFunc(func(attempt int, err error) (time.Duration, error) { retryCount := min(attempt, 7) - delay := (1 << uint(retryCount)) * (rand.Intn(50) + 200) + delay := (1 << uint(retryCount)) * (rand.IntN(50) + 200) return time.Duration(delay) * time.Millisecond, nil })