[TOC] 种子一样,每次运行程序产生的随机数一样 ~~~ import ( "fmt" "math/rand" ) func main() { rand.Seed(666) for i := 0; i <5; i++ { fmt.Println(rand.Int()) } } ~~~ 限制多少以内 ~~~ import ( "fmt" "math/rand" "time" ) func main() { //时间代替 rand.Seed(time.Now().UnixNano()) for i := 0; i <5; i++ { fmt.Println(rand.Intn(100)) } } ~~~