diff --git a/go/tumblrandom/tumblrandom.go b/go/tumblrandom/tumblrandom.go index cc4163d1dc..f6ec2ae4e6 100644 --- a/go/tumblrandom/tumblrandom.go +++ b/go/tumblrandom/tumblrandom.go @@ -12,7 +12,7 @@ import ( "io" "io/fs" "log" - mathrand "math/rand" + "math/big" "net" "net/http" "os" @@ -289,7 +289,12 @@ func (a *app) random(rw http.ResponseWriter, r *http.Request) { return } - n := mathrand.Intn(len(u.Likes)) + bigN, err := rand.Int(rand.Reader, big.NewInt(int64(len(u.Likes)))) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + n := int(bigN.Int64()) l := u.Likes[n] http.Redirect(rw, r, l.PostURL, http.StatusSeeOther) }