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) 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) Uint64n(n uint64) uint64
- type Source
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 ¶ added in v1.3.0
func Entropy128() [16]byte
Entropy128 is a helper function that returns 128 bits of random data.
func Entropy192 ¶ added in v1.3.0
func Entropy192() [24]byte
Entropy192 is a helper function that returns 192 bits of random data.
func Entropy256 ¶ added in v1.3.0
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 ¶ added in v1.3.0
Entropy128 is a helper function that returns 128 bits of random data.
func (*RNG) Entropy192 ¶ added in v1.3.0
Entropy192 is a helper function that returns 192 bits of random data.
func (*RNG) Entropy256 ¶ added in v1.3.0
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.
type Source ¶ added in v1.4.0
type Source struct {
// contains filtered or unexported fields
}
A Source is a math/rand-compatible source of entropy. It is safe for concurrent use by multiple goroutines
func NewSource ¶ added in v1.4.0
func NewSource() *Source
NewSource returns a source for use with the math/rand package.
func (*Source) Int63 ¶ added in v1.4.0
Int63 returns a non-negative random 63-bit integer as an int64.