Created
May 26, 2014 15:57
-
-
Save aanand/3fe874ab984f0b07bd33 to your computer and use it in GitHub Desktop.
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
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