From d457a1187dbbbf08bcce437789732dab02a73b0f Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 27 Apr 2015 00:49:49 +0200 Subject: [PATCH] common: add Hash.Generate --- common/types.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/types.go b/common/types.go index daefcde11e..183d48fb32 100644 --- a/common/types.go +++ b/common/types.go @@ -1,6 +1,10 @@ package common -import "math/big" +import ( + "math/big" + "math/rand" + "reflect" +) const ( hashLength = 32 @@ -48,6 +52,15 @@ func (h *Hash) Set(other Hash) { } } +// Generate implements testing/quick.Generator. +func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value { + m := rand.Intn(len(h)) + for i := len(h) - 1; i > m; i-- { + h[i] = byte(rand.Uint32()) + } + return reflect.ValueOf(h) +} + /////////// Address func BytesToAddress(b []byte) Address { var a Address