Skip to content

Commit

Permalink
Divide by 2 randomHex allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
geobeau committed Apr 20, 2022
1 parent b9e6b1b commit f1926b0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Contains(s []string, e string) bool {
}

func RandomHex(n int) string {
bytes := make([]byte, n)
bytes := make([]byte, n/2+n%2)
if _, err := rand.Read(bytes); err != nil {
PanicOnError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestRandomHexWorks(t *testing.T) {
re, _ := regexp.Compile("^[a-f0-9]{77}$")
hex := utils.RandomHex(77)
if !re.MatchString(hex) {
t.Errorf("RandomHex doesn't work, generated hex: %s", hex)
t.Errorf("RandomHex doesn't work, generated hex: %s (size:%d)", hex, len(hex))
}

}

0 comments on commit f1926b0

Please sign in to comment.