Documentation
¶
Overview ¶
Package randbytes provides interfaces and functions to generate random bytes.
This package is based on the standard library math/rand/v2, which is pseudorandom but reproducible. This package is for scenarios that require not only random data but also the same data next time, such as data for testing. Without the need for reproduction, use crypto/rand.Read instead.
For better performance, all functions in this package are unsafe for concurrency unless otherwise specified.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append generates n random bytes using the specified random value source, appends them to p, and returns the extended byte slice.
The random value source should not be used by others concurrently.
Append panics if the random value source is nil or n is negative.
func Fill ¶
func Fill(src rand.Source, p []byte)
Fill generates random bytes using the specified random value source and writes them into p.
The random value source should not be used by others concurrently.
Fill panics if the random value source is nil.
func Make ¶
Make allocates a []byte with the specified length and fills it with random bytes generated from the specified random value source.
The random value source should not be used by others concurrently.
Make panics if the random value source is nil or the length is negative.
func MakeCapacity ¶
MakeCapacity is like Make but specifies a different capacity.
The random value source should not be used by others concurrently.
MakeCapacity panics if the random value source is nil, the length is negative, or the capacity is less than the length.
func WriteN ¶
func WriteN(src rand.Source, w io.ByteWriter, n int) (written int, err error)
WriteN generates n random bytes using the specified random value source and writes them into the specified byte writer.
The random value source should not be used by others concurrently.
WriteN returns the number of bytes written and any write error encountered.
It panics if the random value source or the byte writer is nil or n is negative.
Types ¶
type Reader ¶
type Reader interface { io.Reader io.ByteReader // Source returns the random value source used by this reader. Source() rand.Source }
Reader is a pseudorandom byte generator.
It combines io.Reader and io.ByteReader. Its method Read always returns the buffer length (i.e., len(p)) and a nil error. Its method ReadByte always returns a nil error as well.
It is based on the standard library math/rand/v2. During the call to its read methods, its random value source should not be used by others concurrently.
func NewReader ¶
func NewReader(src rand.Source) Reader
NewReader creates a new pseudorandom byte generator with the specified random value source.
During the call to the read methods of the returned Reader, the random value source should not be used by others concurrently.
NewReader panics if the random value source is nil.