fix golint issues in core/stringx (#516)

This commit is contained in:
Kevin Wan
2021-02-24 16:09:07 +08:00
committed by GitHub
parent acdaee0fb6
commit 04b0f26182
4 changed files with 23 additions and 2 deletions

View File

@@ -42,10 +42,12 @@ func (ls *lockedSource) Seed(seed int64) {
ls.source.Seed(seed)
}
// Rand returns a random string.
func Rand() string {
return Randn(defaultRandLen)
}
// RandId returns a random id string.
func RandId() string {
b := make([]byte, idLen)
_, err := crand.Read(b)
@@ -56,6 +58,7 @@ func RandId() string {
return fmt.Sprintf("%x%x%x%x", b[0:2], b[2:4], b[4:6], b[6:8])
}
// Randn returns a random string with length n.
func Randn(n int) string {
b := make([]byte, n)
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
@@ -74,6 +77,7 @@ func Randn(n int) string {
return string(b)
}
// Seed sets the seed to seed.
func Seed(seed int64) {
src.Seed(seed)
}