Skip to content

Instantly share code, notes, and snippets.

@mtilson
Last active January 14, 2020 13:47
Show Gist options
  • Save mtilson/77bc03bff69d571d8089e8c863b67a71 to your computer and use it in GitHub Desktop.
Save mtilson/77bc03bff69d571d8089e8c863b67a71 to your computer and use it in GitHub Desktop.
how to generate random data [golang] [20lines]
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