我正在阅读Golang教程,我就是这个部分
package main
import (
"fmt"
"math/rand"
)
func main() {
fmt.Println("My favorite number is", rand.Seed)
}
这会返回My favorite number is 0xb1c20
我一直在阅读https://golang.org/pkg/math/rand/#Seed,但我仍然有点困惑,不知道如何显示十六进制显示一个字符串
答案 0 :(得分:1)
math/rand.Seed
是一个功能;您正在打印功能在内存中的位置。您可能打算做以下事情:
package main
import (
"fmt"
"math/rand"
)
func main() {
rand.Seed(234) // replace with your seed value, or set the seed based off
// of the current time
fmt.Println("My favorite number is", rand.Int())
}