Skip to content

Commit

Permalink
Fix rand source in name (#3070)
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Jun 26, 2024
1 parent ee1db86 commit 3f6a546
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/helpers/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package helpers
import (
"math/rand"
"strings"
"sync"
"time"
"unicode"
)
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 3f6a546

Please sign in to comment.