Skip to content

Instantly share code, notes, and snippets.

@aanand
Created May 26, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aanand/3fe874ab984f0b07bd33 to your computer and use it in GitHub Desktop.
Save aanand/3fe874ab984f0b07bd33 to your computer and use it in GitHub Desktop.
func randomHexString(length int) (string, error) {
chars := "01234567890abcdef"
bytes := make([]byte, length)
for idx, _ := range bytes {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars))))
if err != nil {
return "", err
}
bytes[idx] = chars[num.Int64()]
}
return string(bytes), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment