diff --git a/internal/pkg/agent/application/upgrade/artifact/download/http/verifier_test.go b/internal/pkg/agent/application/upgrade/artifact/download/http/verifier_test.go index 663147ba0a3..20e44a78b69 100644 --- a/internal/pkg/agent/application/upgrade/artifact/download/http/verifier_test.go +++ b/internal/pkg/agent/application/upgrade/artifact/download/http/verifier_test.go @@ -7,7 +7,7 @@ package http import ( "context" "fmt" - "math/rand" + "math/rand/v2" "net/http" "net/http/httptest" "net/url" @@ -111,8 +111,8 @@ func runTests(t *testing.T, testCases []testCase, config *artifact.Config, log * func getRandomTestCases() []testCase { tt := getTestCases() - first := rand.Intn(len(tt)) - second := rand.Intn(len(tt)) + first := rand.IntN(len(tt)) + second := rand.IntN(len(tt)) return []testCase{ tt[first], diff --git a/internal/pkg/agent/application/upgrade/marker_access_test.go b/internal/pkg/agent/application/upgrade/marker_access_test.go index 21f1488ac1d..a32046552db 100644 --- a/internal/pkg/agent/application/upgrade/marker_access_test.go +++ b/internal/pkg/agent/application/upgrade/marker_access_test.go @@ -8,7 +8,7 @@ import ( "context" "errors" "fmt" - "math/rand" + "math/rand/v2" "os" "path/filepath" "sync" @@ -159,7 +159,7 @@ func randomBytes(length int) []byte { var b []byte for i := 0; i < length; i++ { - rune := chars[rand.Intn(len(chars))] + rune := chars[rand.IntN(len(chars))] b = append(b, byte(rune)) } diff --git a/internal/pkg/agent/cmd/enroll_cmd.go b/internal/pkg/agent/cmd/enroll_cmd.go index bbfa3be1f4a..6c1438cb6df 100644 --- a/internal/pkg/agent/cmd/enroll_cmd.go +++ b/internal/pkg/agent/cmd/enroll_cmd.go @@ -9,7 +9,7 @@ import ( "context" "fmt" "io" - "math/rand" + "math/rand/v2" "os" "os/exec" "strings" @@ -704,7 +704,7 @@ func yamlToReader(in interface{}) (io.Reader, error) { } func delay(ctx context.Context, d time.Duration) { - t := time.NewTimer(time.Duration(rand.Int63n(int64(d)))) + t := time.NewTimer(rand.N(d)) defer t.Stop() select { case <-ctx.Done(): diff --git a/internal/pkg/core/backoff/equal_jitter.go b/internal/pkg/core/backoff/equal_jitter.go index 671201f5892..aeba61e7a2d 100644 --- a/internal/pkg/core/backoff/equal_jitter.go +++ b/internal/pkg/core/backoff/equal_jitter.go @@ -5,7 +5,7 @@ package backoff import ( - "math/rand" + "math/rand/v2" "time" ) @@ -30,7 +30,7 @@ func NewEqualJitterBackoff(done <-chan struct{}, init, max time.Duration) Backof done: done, init: init, max: max, - nextRand: time.Duration(rand.Int63n(int64(init))), //nolint:gosec + nextRand: rand.N(init), } } @@ -51,7 +51,7 @@ func (b *EqualJitterBackoff) Wait() bool { backoff := b.NextWait() // increase duration for next wait. - b.nextRand = time.Duration(rand.Int63n(int64(b.duration))) + b.nextRand = rand.N(b.duration) b.duration *= 2 if b.duration > b.max { b.duration = b.max diff --git a/internal/pkg/remote/client.go b/internal/pkg/remote/client.go index 991b7ed55e2..50faf1cd2c7 100644 --- a/internal/pkg/remote/client.go +++ b/internal/pkg/remote/client.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" "io" - "math/rand" + "math/rand/v2" "net/http" "net/url" "sort" diff --git a/internal/pkg/scheduler/scheduler.go b/internal/pkg/scheduler/scheduler.go index c4c9b9d55eb..de5ee3c4581 100644 --- a/internal/pkg/scheduler/scheduler.go +++ b/internal/pkg/scheduler/scheduler.go @@ -5,7 +5,7 @@ package scheduler import ( - "math/rand" + "math/rand/v2" "time" ) @@ -129,6 +129,5 @@ func (p *PeriodicJitter) Stop() { } func (p *PeriodicJitter) delay() time.Duration { - t := int64(p.variance) - return time.Duration(rand.Int63n(t)) + return rand.N(p.variance) } diff --git a/magefile.go b/magefile.go index 55be128a0e6..0ddb0a59178 100644 --- a/magefile.go +++ b/magefile.go @@ -15,7 +15,7 @@ import ( "fmt" "html/template" "log" - "math/rand" + "math/rand/v2" "net/http" "os" "os/exec" diff --git a/testing/integration/install_test.go b/testing/integration/install_test.go index 6e7d4a9496f..f9fae0046fc 100644 --- a/testing/integration/install_test.go +++ b/testing/integration/install_test.go @@ -9,7 +9,7 @@ package integration import ( "context" "fmt" - "math/rand" + "math/rand/v2" "os" "path/filepath" "runtime" @@ -338,7 +338,7 @@ func randStr(length int) string { runes := make([]rune, length) for i := range runes { - runes[i] = letters[rand.Intn(len(letters))] + runes[i] = letters[rand.IntN(len(letters))] } return string(runes)