Go的rand包错误 [英] rand package error in Go
问题描述
我尝试调用rand包(http://golang.org/pkg/rand/)的ExpFloat64()函数。但是,它提供以下错误prog.go:4:导入且未使用:rand prog.go:7:undefined:ExpFloat64。任何人都可以帮助我,为什么它会给出错误?
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())
}
推荐答案
错误消息完美地解释了它 - 在Go中,您无法导入包并且不能使用它们。在这里,它表示你正在导入rand而不是使用它,所以要么使用它,要么不导入它。您的主要功能应该是:
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())
这篇关于Go的rand包错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!