kaspad/util/random/random.go
Svarog 80c445c78b
[NOD-1551] Optimize binary writes + remove redundant VarInt code (#1163)
* [NOD-1551] Optimize binary writes + remove redundant VarInt code

* [NOD-1551] Remove varInt tests

* [NOD-1551] Fix TestBech32 for Go1.15
2020-11-30 13:45:06 +02:00

25 lines
580 B
Go

package random
import (
"crypto/rand"
"io"
"github.com/kaspanet/kaspad/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)
if err != nil {
return 0, err
}
return rv, nil
}
// Uint64 returns a cryptographically random uint64 value.
func Uint64() (uint64, error) {
return randomUint64(rand.Reader)
}