生成随机数字
func RandomInt(start int,end int) int{
rand.Seed(time.Now().UnixNano())
random:=rand.Intn(end-start)
random = start + random
return random
}
生成随机字符串
func RandString(len int) string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
bytes := make([]byte, len)
for i := 0; i < len; i++ {
b := r.Intn(26) + 65
bytes[i] = byte(b)
}
return string(bytes)
}
网友评论