Skip to content

Commit

Permalink
Merge pull request #529 from catatsuy/feature-update-math-rand-import…
Browse files Browse the repository at this point in the history
…s-to-v2

Update math/rand import to v2 and refactor random number generation
  • Loading branch information
catatsuy committed Aug 25, 2024
2 parents 9fa2c45 + 09a1168 commit d195731
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 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,25 +21,20 @@ 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
}

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

func RandomLUNStr(n int) string {
return randomStr(n, lunRunes)
}

func randomStr(n int, s []rune) string {
buf := make([]byte, 0, n)
buf := make([]byte, n)
for i := 0; i < n; i++ {
buf = append(buf, byte(s[random.Int()%len(s)]))
buf[i] = byte(s[mrand.IntN(len(s))])
}
return string(buf)
}

0 comments on commit d195731

Please sign in to comment.