Created
September 6, 2019 07:52
-
-
Save jtbonhomme/0ab59b2c83bf9a0bb7a5741b643c8f52 to your computer and use it in GitHub Desktop.
Use crypto/rand library to generate random numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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