Skip to content

Commit d457a11

Browse files
committed
common: add Hash.Generate
1 parent 72ab6d3 commit d457a11

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

common/types.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package common
22

3-
import "math/big"
3+
import (
4+
"math/big"
5+
"math/rand"
6+
"reflect"
7+
)
48

59
const (
610
hashLength = 32
@@ -48,6 +52,15 @@ func (h *Hash) Set(other Hash) {
4852
}
4953
}
5054

55+
// Generate implements testing/quick.Generator.
56+
func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value {
57+
m := rand.Intn(len(h))
58+
for i := len(h) - 1; i > m; i-- {
59+
h[i] = byte(rand.Uint32())
60+
}
61+
return reflect.ValueOf(h)
62+
}
63+
5164
/////////// Address
5265
func BytesToAddress(b []byte) Address {
5366
var a Address

0 commit comments

Comments
 (0)