Reputation: 3858
I try to call the ExpFloat64() function of the rand package (http://golang.org/pkg/rand/). However, it gives following error "prog.go:4: imported and not used: rand prog.go:7: undefined: ExpFloat64". Can anybody help me why is it giving error ? Code given below.
package main
import "fmt"
import "rand"
func main() {
fmt.Println(ExpFloat64())
}
Upvotes: 1
Views: 626
Reputation: 122469
To add to what Chris Bunch said, if you really wanted to use the names in the package (e.g. ExpFloat64
) directly without using the package name, you can do this:
import . "rand"
Upvotes: 3
Reputation: 89853
The error message explains it perfectly - in Go, you can't import packages and not use them. Here, it says you're importing rand and not using it, so either use it or don't import it. Your main function should be:
fmt.Println(rand.ExpFloat64())
Upvotes: 6