kaspad/util/random/random.go
Svarog 369ec449a8 [NOD-509] Change organization name to kaspanet (#524)
* [NOD-509] Change organization name to kaspanet

* [NOD-509] Reorganize imports
2019-12-08 17:33:42 +02:00

26 lines
618 B
Go

package random
import (
"crypto/rand"
"encoding/binary"
"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, 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)
}