mrand: fix bug in Hex with it not outputting correct number of characters for odd number inputs
This commit is contained in:
parent
8084268bbf
commit
526e35cf3f
@ -25,8 +25,12 @@ func (r Rand) Bytes(n int) []byte {
|
|||||||
|
|
||||||
// Hex returns a random hex string which is n characters long.
|
// Hex returns a random hex string which is n characters long.
|
||||||
func (r Rand) Hex(n int) string {
|
func (r Rand) Hex(n int) string {
|
||||||
|
origN := n
|
||||||
|
if n%2 == 1 {
|
||||||
|
n++
|
||||||
|
}
|
||||||
b := r.Bytes(hex.DecodedLen(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.
|
// Element returns a random element from the given slice.
|
||||||
|
Loading…
Reference in New Issue
Block a user