golang random int

"math/rand"

 

func RandString(length int) string {
rand.Seed(time.Now().UnixNano())
rs := make([]string, length)
for start := 0; start < length; start++ {
t := rand.Intn(3)
if t == 0 {
rs = append(rs, strconv.Itoa(rand.Intn(10)))
} else if t == 1 {
rs = append(rs, string(rand.Intn(26)+65))
} else {
rs = append(rs, string(rand.Intn(26)+97))
}
}
return strings.Join(rs, "")
}

 

r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 100; i++ {
ppp.Port = 10000 + r.Intn(30000)
ppp.Portpwd = RandString(63)
}

posted on 2015-02-02 22:06  默默闯天涯  阅读(588)  评论(0编辑  收藏  举报