将hex更改为string

时间:2016-02-06 19:47:54

标签: go

我正在阅读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,但我仍然有点困惑,不知道如何显示十六进制显示一个字符串

1 个答案:

答案 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())
}