有没有一种类似于Python`secrets`模块的方式来生成Go中具有加密强度的随机数? [重复]

Using python you could use the secrets module like this.

    import secrets
    print(secrets.token_hex(16))

    >>> a67c39a93429f53e5c2a711b0c8455b6

Is there a similar way to do this using Go?

</div>

Use the crypto/rand package, something like this:

b := make([]byte, length)
_, err := rand.Read(b)
if err != nil {
    fmt.Println("error reading random token:", err)
    return nil
}