mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-1551] Optimize binary writes + remove redundant VarInt code * [NOD-1551] Remove varInt tests * [NOD-1551] Fix TestBech32 for Go1.15
25 lines
580 B
Go
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)
|
|
}
|