diff --git a/build.go b/build.go index 493ae2e1..84b57a03 100644 --- a/build.go +++ b/build.go @@ -11,7 +11,7 @@ import ( "html/template" "io" "math/big" - "math/rand" + "math/rand/v2" "net/http" "net/url" "os" @@ -2963,7 +2963,7 @@ func selectRandomPhoto(photos []*Photo) *Photo { } //nolint:gosec - return randomPhotos[rand.Intn(len(randomPhotos))] + return randomPhotos[rand.IntN(len(randomPhotos))] } // Gets a pointer to a tag just to work around the fact that you can take the diff --git a/modules/stemplate/stemplate.go b/modules/stemplate/stemplate.go index 32146dd9..8bbbfa2a 100644 --- a/modules/stemplate/stemplate.go +++ b/modules/stemplate/stemplate.go @@ -6,7 +6,7 @@ import ( "fmt" "html/template" "math" - "math/rand" + "math/rand/v2" "net/url" "os" "path/filepath" @@ -33,7 +33,7 @@ var FuncMap = template.FuncMap{ "NanoglyphSignup": nanoglyphSignup, "NumberWithDelimiter": numberWithDelimiter, "Pace": pace, - "RandIntn": randIntn, + "RandIntN": rand.IntN, "RenderPublishingInfo": renderPublishingInfo, "RetinaImageAlt": RetinaImageAlt, "Sub": sub, @@ -222,11 +222,6 @@ func pace(distance float64, duration time.Duration) string { return fmt.Sprintf("%v:%02d", minutes, seconds) } -func randIntn(bound int) int { - //nolint:gosec - return rand.Intn(bound) -} - func renderPublishingInfo(info map[string]string) template.HTML { s := "" diff --git a/modules/stemplate/stemplate_test.go b/modules/stemplate/stemplate_test.go index 08c6fb71..924da73a 100644 --- a/modules/stemplate/stemplate_test.go +++ b/modules/stemplate/stemplate_test.go @@ -117,10 +117,6 @@ func TestPace(t *testing.T) { assert.Equal(t, "7:31", pace(133.0, d)) } -func TestRandIntn(t *testing.T) { - assert.Equal(t, 0, randIntn(1)) -} - func TestRetinaImageAlt(t *testing.T) { assert.Equal(t, `alt text
{{- with (index .Entry.Photos 0) -}} - {{LazyRetinaImageLightbox (RandIntn 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} + {{LazyRetinaImageLightbox (RandIntN 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} {{- end -}}
{{- with (index .Entry.Photos 1) -}} - {{LazyRetinaImageLightbox (RandIntn 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} + {{LazyRetinaImageLightbox (RandIntN 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} {{- end -}}
{{- with (index .Entry.Photos 2) -}} - {{LazyRetinaImageLightbox (RandIntn 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} + {{LazyRetinaImageLightbox (RandIntN 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} {{- end -}}
@@ -40,13 +40,13 @@
{{- with (index .Entry.Photos 0) -}} - {{LazyRetinaImageLightbox (RandIntn 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} + {{LazyRetinaImageLightbox (RandIntN 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} {{- end -}}
{{- with (index .Entry.Photos 1) -}} - {{LazyRetinaImageLightbox (RandIntn 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} + {{LazyRetinaImageLightbox (RandIntN 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} {{- end -}}
@@ -55,7 +55,7 @@
{{- with (index .Entry.Photos 0) -}} - {{LazyRetinaImageLightbox (RandIntn 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} + {{LazyRetinaImageLightbox (RandIntN 100) "/photographs/sequences/" (printf "%s_large" .Slug) .TargetExt .Portrait $linkOverride}} {{- end -}}