Skip to content

Commit

Permalink
feat: rand seed compatible with >=go1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
amlivedn authored and wellle committed Nov 28, 2023
1 parent 2c434d4 commit e8bf6b5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"time"
)

func init() {
rand.Seed(time.Now().UnixNano())
}
var (
source = rand.NewSource(time.Now().UnixNano())
random = rand.New(source)
)

// standard characters used by uniuri
const letterBytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Expand All @@ -16,7 +17,7 @@ const letterBytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456
func RandomString(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
b[i] = letterBytes[random.Intn(len(letterBytes))]
}
return string(b)
}

0 comments on commit e8bf6b5

Please sign in to comment.