Skip to content

Commit 023c3e9

Browse files
committed
Merge branch 'master' of gitlab.ricebook.net:platform/core
2 parents 9836659 + a092b04 commit 023c3e9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

utils/utils.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package utils
22

33
import (
4+
"crypto/rand"
45
"fmt"
5-
"math/rand"
6+
"math/big"
67
"os"
78
"sort"
89
"strings"
9-
"time"
1010

1111
engineapi "github.com/docker/engine-api/client"
1212
"gitlab.ricebook.net/platform/core/types"
@@ -20,10 +20,14 @@ const (
2020
)
2121

2222
func RandomString(n int) string {
23-
rand.Seed(time.Now().UnixNano())
2423
r := make([]byte, n)
2524
for i := 0; i < n; i++ {
26-
r[i] = letters[rand.Intn(len(letters))]
25+
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
26+
// 没那么惨吧
27+
if err != nil {
28+
continue
29+
}
30+
r[i] = letters[n.Int64()]
2731
}
2832
return string(r)
2933
}

0 commit comments

Comments
 (0)