Replaced math/rand with crypto/rand
This commit is contained in:
parent
d869a375ab
commit
caf1b1889c
27
cmd/files.go
27
cmd/files.go
|
@ -11,8 +11,9 @@ import (
|
|||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"math/big"
|
||||
|
||||
"math/rand"
|
||||
"crypto/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -618,16 +619,24 @@ func pickFile(args []string, filters *Filters, sort string, index *Index) (strin
|
|||
return "", ErrNoImagesFound
|
||||
}
|
||||
|
||||
r := rand.Intn(fileCount)
|
||||
|
||||
for i := 0; i < fileCount; i++ {
|
||||
if r >= (fileCount - 1) {
|
||||
r = 0
|
||||
} else {
|
||||
r++
|
||||
r, err := rand.Int(rand.Reader, big.NewInt(int64(fileCount-2)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
filePath := fileList[r]
|
||||
val, err := strconv.Atoi(strconv.FormatInt(r.Int64(), 10))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for i := 0; i < fileCount; i++ {
|
||||
if val >= fileCount {
|
||||
val = 0
|
||||
} else {
|
||||
val++
|
||||
}
|
||||
|
||||
filePath := fileList[val]
|
||||
|
||||
if !fromCache {
|
||||
image, err := isSupportedFileType(filePath)
|
||||
|
|
|
@ -17,7 +17,7 @@ var (
|
|||
)
|
||||
|
||||
const (
|
||||
Version string = "0.59.4"
|
||||
Version string = "0.60.0"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -1101,8 +1100,6 @@ func ServePage(args []string) error {
|
|||
fmt.Printf("WARNING! Files *will* be deleted after serving!\n\n")
|
||||
}
|
||||
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
mux := httprouter.New()
|
||||
|
||||
index := &Index{
|
||||
|
|
Loading…
Reference in New Issue