p2p: Add test vectors for deriving secrets (#2120)

These test vectors are needed for comparison with the Rust implementation.
To implement this effectively, a "RandBool" method was added to cmn.Rand.
This commit is contained in:
Dev Ojha
2018-08-01 12:06:30 -07:00
committed by Alexander Simmerl
parent dde96b75ce
commit 023bb99eb0
3 changed files with 111 additions and 0 deletions

View File

@ -109,6 +109,10 @@ func RandInt63n(n int64) int64 {
return grand.Int63n(n)
}
func RandBool() bool {
return grand.Bool()
}
func RandFloat32() float32 {
return grand.Float32()
}
@ -274,6 +278,13 @@ func (r *Rand) Intn(n int) int {
return i
}
// Bool returns a uniformly random boolean
func (r *Rand) Bool() bool {
// See https://github.com/golang/go/issues/23804#issuecomment-365370418
// for reasoning behind computing like this
return r.Int63()%2 == 0
}
// Perm returns a pseudo-random permutation of n integers in [0, n).
func (r *Rand) Perm(n int) []int {
r.Lock()