aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/rand.go
blob: 91dafec7ed6f960c5c731ac215bc4c09dcfb88e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package ethutil

import (
    "crypto/rand"
    "encoding/binary"
    "io"
)

func randomUint64(r io.Reader) (uint64, error) {
    b := make([]byte, 8)
    n, err := r.Read(b)
    if n != len(b) {
        return 0, io.ErrShortBuffer
    }
    if err != nil {
        return 0, err
    }
    return binary.BigEndian.Uint64(b), nil
}

// RandomUint64 returns a cryptographically random uint64 value.
func RandomUint64() (uint64, error) {
    return randomUint64(rand.Reader)
}