Documentation ¶
Index ¶
- Variables
- func BigIntn(n *big.Int) *big.Int
- func Bytes(n int) []byte
- func Entropy128() [16]byte
- func Entropy192() [24]byte
- func Entropy256() [32]byte
- func Float64() float64
- func Intn(n int) int
- func Perm(n int) []int
- func Read(b []byte) (int, error)
- func Shuffle(n int, swap func(i, j int))
- func Uint64n(n uint64) uint64
- type RNG
- func (r *RNG) BigIntn(n *big.Int) *big.Int
- func (r *RNG) Bytes(n int) []byte
- func (r *RNG) Entropy128() (entropy [16]byte)
- func (r *RNG) Entropy192() (entropy [24]byte)
- func (r *RNG) Entropy256() (entropy [32]byte)
- func (r *RNG) Float64() float64
- func (r *RNG) Intn(n int) int
- func (r *RNG) Marshal() []byte
- func (r *RNG) Perm(n int) []int
- func (r *RNG) Read(b []byte) (int, error)
- func (r *RNG) Shuffle(n int, swap func(i, j int))
- func (r *RNG) Skip(nBytes int) (int, error)
- func (r *RNG) Uint64n(n uint64) uint64
Constants ¶
This section is empty.
Variables ¶
var Reader rngReader
Reader is a global, shared instance of a cryptographically strong pseudo- random generator. Reader is safe for concurrent use by multiple goroutines.
Functions ¶
func Entropy128 ¶
func Entropy128() [16]byte
Entropy128 is a helper function that returns 128 bits of random data.
func Entropy192 ¶
func Entropy192() [24]byte
Entropy192 is a helper function that returns 192 bits of random data.
func Entropy256 ¶
func Entropy256() [32]byte
Entropy256 is a helper function that returns 256 bits of random data.
Types ¶
type RNG ¶
type RNG struct {
// contains filtered or unexported fields
}
An RNG is a cryptographically-strong RNG constructed from the ChaCha stream cipher.
func New ¶
func New() *RNG
New returns a new RNG instance. The instance is seeded with entropy from crypto/rand, albeit indirectly; its seed is generated by a global "master" RNG, which itself is seeded from crypto/rand. This means the frand package only reads system entropy once, at startup.
func NewCustom ¶
NewCustom returns a new RNG instance seeded with the provided entropy and using the specified buffer size and number of ChaCha rounds. It panics if len(seed) != 32, bufsize < 32, or rounds != 8, 12 or 20.
func (*RNG) Entropy128 ¶
Entropy128 is a helper function that returns 128 bits of random data.
func (*RNG) Entropy192 ¶
Entropy192 is a helper function that returns 192 bits of random data.
func (*RNG) Entropy256 ¶
Entropy256 is a helper function that returns 256 bits of random data.
func (*RNG) Read ¶
Read fills b with random data. It always returns len(b), nil.
For performance reasons, calling Read once on a "large" buffer (larger than the RNG's internal buffer) will produce different output than calling Read multiple times on smaller buffers. If deterministic output is required, clients should call Read in a loop; when copying to an io.Writer, use io.CopyBuffer instead of io.Copy. Callers should also be aware that b is xored with random data, not directly overwritten; this means that the new contents of b depend on its previous contents.
func (*RNG) Shuffle ¶
Shuffle randomly permutes n elements by repeatedly calling swap in the range [0,n). It panics if n < 0.