Go语言包名冲突问题:math/rand 和 crypto/rand 导入与引用

Go 语言自带源代码库有两个 rand 包,如果同时使用会造成冲突,导入时可利用包的别名机制解决此问题。参见下面示例代码:

import (
    ...
    math_rand "math/rand"
    crypt_rand "crypto/rand"
    ...
)

func main() {
    ...
    math_rand.Seed(time.Now().Unix())
    ...
    key, err := rsa.GenerateKey(crypt_rand.Reader, bits)
    ...
}

猜你喜欢

转载自blog.csdn.net/quicmous/article/details/80479841