Skip to content

Commit

Permalink
Replace the random char seed to global rand to avoid collision (#1729)
Browse files Browse the repository at this point in the history
#1727 changed the random string causing namespaces test fails.

This fixes #1728
  • Loading branch information
git-hulk authored Sep 3, 2023
1 parent e917552 commit 0049249
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tests/gocase/util/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"math/rand"
"strings"
"time"
)

func RandPath[T any](f ...func() T) T {
Expand Down Expand Up @@ -58,7 +57,7 @@ const (
)

func RandString(min, max int, typ RandStringType) string {
return RandStringWithSeed(min, max, typ, time.Now().UnixNano())
return RandStringWithSeed(min, max, typ, rand.Int63())
}

func RandStringWithSeed(min, max int, typ RandStringType, seed int64) string {
Expand All @@ -75,7 +74,7 @@ func RandStringWithSeed(min, max int, typ RandStringType, seed int64) string {

var sb strings.Builder
for ; length > 0; length-- {
s := fmt.Sprintf("%c", minVal+int(r.Int31n(int32(maxVal-minVal+1))))
s := fmt.Sprintf("%c", minVal+r.Intn(maxVal-minVal+1))
sb.WriteString(s)
}
return sb.String()
Expand Down

0 comments on commit 0049249

Please sign in to comment.