GOLANG学习9. 随机数
package main
import (
"fmt"
"math/rand"
"time"
)
func init() {
//随机种子纳秒级
rand.Seed(time.Now().UnixNano())
}
func main() {
//随机种子秒级
//rand.Seed(time.Now().Unix())
for i := 0; i < 10; i++ {
a := rand.Int()
fmt.Println(a)
}
//随机小于100的整数
for i := 0; i < 10; i++ {
a := rand.Intn(100)
fmt.Println(a)
}
for i := 0; i < 10; i++ {
a := rand.Float32()
fmt.Println(a)
}
}