From 36d98450dcd3ed9ce59df2bf86c5cd1c23488fd3 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Thu, 1 Jan 2026 17:25:45 +0800 Subject: [PATCH] use math/rand/v2 instead of math/rand --- cache.go | 4 ++-- certificates.go | 4 ++-- config.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cache.go b/cache.go index 3b5cfb0b..8f325576 100644 --- a/cache.go +++ b/cache.go @@ -16,7 +16,7 @@ package certmagic import ( "fmt" - weakrand "math/rand" + weakrand "math/rand/v2" "strings" "sync" "time" @@ -244,7 +244,7 @@ func (certCache *Cache) unsyncedCacheCertificate(cert Certificate) { // map with less code, that is a heavily skewed eviction // strategy; generating random numbers is cheap and // ensures a much better distribution. - rnd := weakrand.Intn(cacheSize) + rnd := weakrand.IntN(cacheSize) i := 0 for _, randomCert := range certCache.cache { if i >= rnd && randomCert.managed { // don't evict manually-loaded certs diff --git a/certificates.go b/certificates.go index e0246dde..76087fc1 100644 --- a/certificates.go +++ b/certificates.go @@ -21,7 +21,7 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" + "math/rand/v2" "net" "os" "strings" @@ -128,7 +128,7 @@ func (cfg *Config) certNeedsRenewal(leaf *x509.Certificate, ari acme.RenewalInfo if selectedTime.IsZero() && (!ari.SuggestedWindow.Start.IsZero() && !ari.SuggestedWindow.End.IsZero()) { start, end := ari.SuggestedWindow.Start.Unix()+1, ari.SuggestedWindow.End.Unix() - selectedTime = time.Unix(rand.Int63n(end-start)+start, 0).UTC() + selectedTime = time.Unix(rand.Int64N(end-start)+start, 0).UTC() logger.Warn("no renewal time had been selected with ARI; chose an ephemeral one for now", zap.Time("ephemeral_selected_time", selectedTime)) } diff --git a/config.go b/config.go index 419b3dcb..81f7a170 100644 --- a/config.go +++ b/config.go @@ -28,7 +28,7 @@ import ( "errors" "fmt" "io/fs" - weakrand "math/rand" + weakrand "math/rand/v2" "net" "net/http" "net/url" @@ -1236,7 +1236,7 @@ func (cfg *Config) checkStorage(ctx context.Context) error { } key := fmt.Sprintf("rw_test_%d", weakrand.Int()) contents := make([]byte, 1024*10) // size sufficient for one or two ACME resources - _, err := weakrand.Read(contents) + _, err := rand.Read(contents) if err != nil { return err }