random: optimize allocation & simplify loop
This commit is contained in:
parent
4682b3a9d2
commit
5a8af5500b
|
@ -25,8 +25,9 @@ func AlphaNumUpper(length int) string { return String(PossibleAlphaNumUpper, len
|
|||
|
||||
func String(chooseFrom string, length int) (randomString string) {
|
||||
cflen := len(chooseFrom)
|
||||
for i := 0; i < length; i++ {
|
||||
randomString += string(chooseFrom[rnd.Intn(cflen)])
|
||||
bytes := make([]byte, length)
|
||||
for i := range bytes {
|
||||
bytes[i] = chooseFrom[rnd.Intn(cflen)]
|
||||
}
|
||||
return
|
||||
return string(bytes)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue