Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to math/rand/v2 #377

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"html/template"
"io"
"math/big"
"math/rand"
"math/rand/v2"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions modules/stemplate/stemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"html/template"
"math"
"math/rand"
"math/rand/v2"
"net/url"
"os"
"path/filepath"
Expand All @@ -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,
Expand Down Expand Up @@ -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 := ""

Expand Down
4 changes: 0 additions & 4 deletions modules/stemplate/stemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
`<img alt="alt text" loading="lazy" src="/photographs/other/001.jpg" `+
Expand Down
12 changes: 6 additions & 6 deletions views/sequences/_entry.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
<div class="flex flex-col">
<div class="mb-0.5">
{{- 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 -}}
</div>

<div class="md:flex md:flex-row md:mb-0.5">
<div class="mb-0.5 md:mr-0.5 md:mb-0">
{{- 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 -}}
</div>

<div class="mb-0.5 md:ml-0.5 md:mb-0">
{{- 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 -}}
</div>
</div>
Expand All @@ -40,13 +40,13 @@
<div class="md:flex md:flex-row mb-0.5">
<div class="mb-0.5 mr-0.5 md:mb-0">
{{- 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 -}}
</div>

<div class="mb-0.5 ml-0.5 md:mb-0">
{{- 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 -}}
</div>
</div>
Expand All @@ -55,7 +55,7 @@

<div class="mb-0.5">
{{- 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 -}}
</div>

Expand Down
Loading