From 526e35cf3f0d213495b80e9dbf4e74d78c9747f6 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Mon, 13 Aug 2018 19:40:15 -0400 Subject: [PATCH] mrand: fix bug in Hex with it not outputting correct number of characters for odd number inputs --- mrand/mrand.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mrand/mrand.go b/mrand/mrand.go index efe3352..6ff5242 100644 --- a/mrand/mrand.go +++ b/mrand/mrand.go @@ -25,8 +25,12 @@ func (r Rand) Bytes(n int) []byte { // Hex returns a random hex string which is n characters long. func (r Rand) Hex(n int) string { + origN := n + if n%2 == 1 { + n++ + } b := r.Bytes(hex.DecodedLen(n)) - return hex.EncodeToString(b) + return hex.EncodeToString(b)[:origN] } // Element returns a random element from the given slice.