Last active
January 14, 2020 13:47
-
-
Save mtilson/77bc03bff69d571d8089e8c863b67a71 to your computer and use it in GitHub Desktop.
how to generate random data [golang] [20lines]
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" | |
"encoding/hex" | |
"fmt" | |
) | |
func main() { | |
src := make([]byte, 4) | |
_, err := rand.Read(src) | |
if err != nil { | |
fmt.Println("error: ", err) | |
return | |
} | |
fmt.Printf("random bytes: %s\n", hex.EncodeToString(src)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment