Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the random char seed to global rand to avoid collision #1729

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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