初试

每个 Go 程序都是由包组成的。

程序运行的入口是包 `main`。

这个程序使用并导入了包 "fmt" 和 `"math/rand"`。

按照惯例,包名与导入路径的最后一个目录一致。例如,`"math/rand"` 包由 package rand 语句开始。

注意: 这个程序的运行环境是固定的,因此 rand.Intn 总是会返回相同的数字。 (为了得到不同的数字,需要生成不同的种子数,参阅 rand.Seed。)

package main

import (
    "fmt"
    "math/rand"
)

func main() {
    fmt.Println("My favorite number is", rand.Intn(10))
}
DEMO

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2021-07-15
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-08
  • 2021-12-27
  • 2022-12-23
  • 2021-06-14
  • 2021-11-05
  • 2021-05-19
相关资源
相似解决方案