You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
387 B
25 lines
387 B
4 years ago
|
package tools
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
// 随机数种子
|
||
|
rand.Seed(time.Now().UnixNano())
|
||
|
}
|
||
|
|
||
|
// @Style 生成随机数
|
||
|
func RandStr(n int, str ...string) string {
|
||
|
s := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||
|
if len(str) > 0 {
|
||
|
s = str[0]
|
||
|
}
|
||
|
res := ""
|
||
|
for i := 0; i < n; i++ {
|
||
|
res += string(s[rand.Intn(len(s))])
|
||
|
}
|
||
|
return res
|
||
|
}
|