2021-08-26 18:50:14 +08:00
|
|
|
/**
|
2022-10-31 17:22:49 +08:00
|
|
|
* @Author: Echo
|
|
|
|
* @Email: 1711788888@qq.com
|
2021-08-26 18:50:14 +08:00
|
|
|
* @Date: 2021/8/26 4:51 下午
|
|
|
|
* @Desc: TODO
|
|
|
|
*/
|
|
|
|
|
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var seedStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
|
|
|
|
// RandStr generate a string of specified length.
|
|
|
|
func RandStr(length int) (lastStr string) {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
2022-10-31 17:22:49 +08:00
|
|
|
|
2021-08-26 18:50:14 +08:00
|
|
|
pos, seedLen := 0, len(seedStr)
|
|
|
|
for i := 0; i < length; i++ {
|
|
|
|
pos = rand.Intn(seedLen)
|
|
|
|
lastStr += seedStr[pos : pos+1]
|
|
|
|
}
|
2022-10-31 17:22:49 +08:00
|
|
|
|
2021-08-26 18:50:14 +08:00
|
|
|
return lastStr
|
|
|
|
}
|