|
|
@@ -2,9 +2,9 @@ package utils
|
|
2
|
2
|
|
|
3
|
3
|
import (
|
|
4
|
4
|
"crypto/md5"
|
|
|
5
|
+ crand "crypto/rand"
|
|
5
|
6
|
"encoding/json"
|
|
6
|
7
|
"fmt"
|
|
7
|
|
- "math/rand"
|
|
8
|
8
|
"reflect"
|
|
9
|
9
|
"runtime/debug"
|
|
10
|
10
|
"strings"
|
|
|
@@ -69,8 +69,12 @@ func RandomString(n int) string {
|
|
69
|
69
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
70
|
70
|
length := len(letterBytes)
|
|
71
|
71
|
b := make([]byte, n)
|
|
72
|
|
- for i := range b {
|
|
73
|
|
- b[i] = letterBytes[rand.Intn(length)]
|
|
|
72
|
+ randomBytes := make([]byte, n)
|
|
|
73
|
+ if _, err := crand.Read(randomBytes); err != nil {
|
|
|
74
|
+ return ""
|
|
|
75
|
+ }
|
|
|
76
|
+ for i, rb := range randomBytes {
|
|
|
77
|
+ b[i] = letterBytes[int(rb)%length]
|
|
74
|
78
|
}
|
|
75
|
79
|
return string(b)
|
|
76
|
80
|
}
|