Skip to content

Instantly share code, notes, and snippets.

@jtbonhomme
Created September 6, 2019 07:52
Show Gist options
  • Save jtbonhomme/0ab59b2c83bf9a0bb7a5741b643c8f52 to your computer and use it in GitHub Desktop.
Save jtbonhomme/0ab59b2c83bf9a0bb7a5741b643c8f52 to your computer and use it in GitHub Desktop.
Use crypto/rand library to generate random numbers
package main
import (
"crypto/rand"
"fmt"
)
func main() {
c := 10
b := make([]byte, c)
_, err := rand.Read(b)
if err != nil {
fmt.Println("error:", err)
return
}
// The slice should now contain random bytes instead of only zeroes.
fmt.Printf("%#v\n", b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment