Should you wish to generate more secure pseudo-random numbers in Go, you should use the crypto/rand package, which implements a cryptographically secure pseudo-random number generator and is the subject of this section.
The use of the crypto/rand package will be illustrated using the Go code of cryptoRand.go, which is going to be presented in three parts.
The first part of cryptoRand.go is as follows:
package main import ( "crypto/rand" "encoding/base64" "fmt" "os" "strconv" ) func generateBytes(n int64) ([]byte, error) { b := make([]byte, n) _, err := rand.Read(b) if err != nil { return nil, err } return b, nil }
The second part of cryptoRand.go contains the following Go code:
func generatePass(s int64) (string, error) { ...