Skip to content

Commit

Permalink
Update math/rand import to v2 and refactor random number generation
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy committed Aug 25, 2024
1 parent 9fa2c45 commit b055c3f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions benchmarker/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"crypto/md5"
"fmt"
"io"
mrand "math/rand"
"time"
mrand "math/rand/v2"
)

func GetMD5(data []byte) string {
Expand All @@ -22,15 +21,14 @@ func GetMD5ByIO(r io.Reader) string {

var (
lunRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
random = mrand.New(mrand.NewSource(time.Now().UnixNano()))
)

func RandomNumber(max int) int {
return random.Int() % max
return mrand.Int() % max
}

func RandomNumberRange(min, max int) int {
return random.Int()%(max-min+1) + min
return mrand.Int()%(max-min+1) + min
}

func RandomLUNStr(n int) string {
Expand All @@ -40,7 +38,7 @@ func RandomLUNStr(n int) string {
func randomStr(n int, s []rune) string {
buf := make([]byte, 0, n)
for i := 0; i < n; i++ {
buf = append(buf, byte(s[random.Int()%len(s)]))
buf = append(buf, byte(s[mrand.Int()%len(s)]))
}
return string(buf)
}

0 comments on commit b055c3f

Please sign in to comment.