Skip to content

Commit

Permalink
🐛 set random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Feb 4, 2022
1 parent 86cda58 commit a229035
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions drivers/189/189.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
log "github.com/sirupsen/logrus"
"io"
"math"
mathRand "math/rand"
"net/http"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -462,7 +461,7 @@ func (driver Cloud189) UploadRequest(uri string, form map[string]string, account
c := strconv.FormatInt(time.Now().UnixMilli(), 10)
r := Random("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx")
l := Random("xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx")
l = l[0 : 16+int(16*mathRand.Float32())]
l = l[0 : 16+int(16*utils.Rand.Float32())]

e := qs(form)
data := AesEncrypt([]byte(e), []byte(l[0:16]))
Expand Down
7 changes: 3 additions & 4 deletions drivers/189/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ import (
"encoding/pem"
"fmt"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
mathRand "math/rand"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)

func random() string {
return fmt.Sprintf("0.%17v", mathRand.New(mathRand.NewSource(time.Now().UnixNano())).Int63n(100000000000000000))
return fmt.Sprintf("0.%17v", utils.Rand.Int63n(100000000000000000))
}

func RsaEncode(origData []byte, j_rsakey string, hex bool) string {
Expand Down Expand Up @@ -169,7 +168,7 @@ func Random(v string) string {
reg := regexp.MustCompilePOSIX("[xy]")
data := reg.ReplaceAllFunc([]byte(v), func(msg []byte) []byte {
var i int64
t := int64(16 * mathRand.Float32())
t := int64(16 * utils.Rand.Float32())
if msg[0] == 120 {
i = t
} else {
Expand Down
11 changes: 10 additions & 1 deletion utils/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ package utils
import (
"math/rand"
"strings"
"time"
)

var Rand *rand.Rand

func init() {
s := rand.NewSource(time.Now().UnixNano())
Rand = rand.New(s)
}

func RandomStr(n int) string {

builder := strings.Builder{}
t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
for i := 0; i < n; i++ {
r := rand.Intn(len(t))
r := Rand.Intn(len(t))
builder.WriteString(t[r : r+1])
}
return builder.String()
Expand Down

0 comments on commit a229035

Please sign in to comment.