kaspad/util/random/random.go
Ori Newman 1da045d1b9 [NOD-30] move wire.RandomUint64() and binarySerializer to util (#204)
* [NOD-30] move wire.RandomUint64() and binarySerializer to util

* [NOD-30] change const style
2019-03-12 13:03:08 +02:00

26 lines
615 B
Go

package random
import (
"crypto/rand"
"encoding/binary"
"io"
"github.com/daglabs/btcd/util/binaryserializer"
)
// randomUint64 returns a cryptographically random uint64 value. This
// unexported version takes a reader primarily to ensure the error paths
// can be properly tested by passing a fake reader in the tests.
func randomUint64(r io.Reader) (uint64, error) {
rv, err := binaryserializer.Uint64(r, binary.BigEndian)
if err != nil {
return 0, err
}
return rv, nil
}
// Uint64 returns a cryptographically random uint64 value.
func Uint64() (uint64, error) {
return randomUint64(rand.Reader)
}