📌  相关文章
📜  随机数 golang - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:45:00.377000             🧑  作者: Mango

代码示例2
package main
import (
    "fmt"
    "math/rand"
    "time"    #ADDED
)

func main() {
    // Seed should be set once, better spot is func init()
    rand.Seed(time.Now().UTC().UnixNano())   #ADDED
    fmt.Println(randInt(1, 1000))
}

func randInt(min int, max int) int {
    return min + rand.Intn(max-min)
}