mirror of https://github.com/knative/pkg.git
Fix rand source in name (#3070)
This commit is contained in:
parent
ee1db869c7
commit
3f6a546ac3
|
|
@ -19,6 +19,7 @@ package helpers
|
|||
import (
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
|
@ -32,7 +33,10 @@ const (
|
|||
testNamePrefix = "Test"
|
||||
)
|
||||
|
||||
var nameRand *rand.Rand
|
||||
var (
|
||||
nameRand *rand.Rand
|
||||
nameMu sync.Mutex
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Properly seed the random number generator so RandomString() is actually random.
|
||||
|
|
@ -75,9 +79,11 @@ func AppendRandomString(prefix string) string {
|
|||
// RandomString will generate a random string.
|
||||
func RandomString() string {
|
||||
suffix := make([]byte, randSuffixLen)
|
||||
nameMu.Lock()
|
||||
for i := range suffix {
|
||||
suffix[i] = letterBytes[nameRand.Intn(len(letterBytes))]
|
||||
}
|
||||
nameMu.Unlock()
|
||||
return string(suffix)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue