Skip to content

Commit

Permalink
don't use deprecated rand.Seed
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Aug 9, 2023
1 parent 2e990a9 commit f96f6af
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/insecurerandstr/random_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"time"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var (
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func init() {
rand.Seed(time.Now().UnixNano())
}
randStr = rand.New(rand.NewSource(time.Now().UnixNano()))
)

// RandStr returns a random string of the given length.
func RandStr(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
b[i] = letters[randStr.Intn(len(letters))]
}
return string(b)
}

0 comments on commit f96f6af

Please sign in to comment.