Skip to content

Commit e8bf6b5

Browse files
amlivednwellle
authored andcommitted
feat: rand seed compatible with >=go1.20
1 parent 2c434d4 commit e8bf6b5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

rand.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"time"
66
)
77

8-
func init() {
9-
rand.Seed(time.Now().UnixNano())
10-
}
8+
var (
9+
source = rand.NewSource(time.Now().UnixNano())
10+
random = rand.New(source)
11+
)
1112

1213
// standard characters used by uniuri
1314
const letterBytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
@@ -16,7 +17,7 @@ const letterBytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456
1617
func RandomString(n int) string {
1718
b := make([]byte, n)
1819
for i := range b {
19-
b[i] = letterBytes[rand.Intn(len(letterBytes))]
20+
b[i] = letterBytes[random.Intn(len(letterBytes))]
2021
}
2122
return string(b)
2223
}

0 commit comments

Comments
 (0)