Home Ask Login Register

Developers Planet

Your answer is one click away!

nadermx February 2016

Change hex to string

I'm going through the Golang tutorial, and I am on this part

package main

import (
    "fmt"
    "math/rand"
)

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

This returns My favorite number is 0xb1c20

I have been reading on https://golang.org/pkg/math/rand/#Seed but I'm still a bit confused as to how have it instead of show the hex show a string

Answers


Tim Cooper February 2016

math/rand.Seed is a function; you are printing the function's location in memory. You probably meant to do something like the following:

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

Post Status

Asked in February 2016
Viewed 3,895 times
Voted 14
Answered 1 times

Search




Leave an answer


Quote of the day: live life