package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
// 利用系统时间生成种子
rand.Seed(time.Now().Unix())
// 生成 [0,n) 的随机数
fmt.Println(rand.Intn(10))
}
Go Playground: https://go.dev/play/p/DXTqGHJLPXj
标签:rand,fmt,生成,随机数,Go,main From: https://www.cnblogs.com/kangbo/p/17073455.html