tumblrandom: use better random
This commit is contained in:
parent
b3cd894f7c
commit
b3008a51c7
1 changed files with 7 additions and 2 deletions
|
@ -12,7 +12,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
mathrand "math/rand"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -289,7 +289,12 @@ func (a *app) random(rw http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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]
|
l := u.Likes[n]
|
||||||
http.Redirect(rw, r, l.PostURL, http.StatusSeeOther)
|
http.Redirect(rw, r, l.PostURL, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue