go语言——随机数
// +build ignore
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
num1 := rand.Int()
fmt.Println(num1)
for i := 1; i < 10; i++ {
num := rand.Intn(10)
fmt.Print(num,"\t")
}
fmt.Println()
rand.Seed(100)
num2 := rand.Intn(10)
fmt.Println(num2)
t1 := time.Now()
fmt.Println(t1)
//时间戳,1970.1.1
t2 := t1.Unix()
fmt.Println(t2)
t3 := t1.UnixNano //纳秒
fmt.Println(t3)
//引入时间戳作为种子,防止每次运行生成的数字一样
rand.Seed(time.Now().UnixNano())
for i := 1; i < 10; i++ {
num := rand.Intn(10)
fmt.Print(num,"\t")
}
}