Imports #
"internal/byteorder"
"internal/goarch"
"unsafe"
"internal/byteorder"
"internal/goarch"
"unsafe"
const chunk = 32
const ctrInc = 4
const ctrMax = 16
const reseed = 4
A State holds the state for a single random generator. It must be used from one goroutine at a time. If used by multiple goroutines at a time, the goroutines may see the same random values, but the code will not crash or cause out-of-bounds memory accesses.
type State struct {
buf [32]uint64
seed [4]uint64
i uint32
n uint32
c uint32
}
type errUnmarshalChaCha8 struct {
}
func (*errUnmarshalChaCha8) Error() string
Init seeds the State with the given seed value.
func (s *State) Init(seed [32]byte)
Init64 seeds the state with the given seed value.
func (s *State) Init64(seed [4]uint64)
Marshal marshals the state into a byte slice. Marshal and Unmarshal are functions, not methods, so that they will not be linked into the runtime when it uses the State struct, since the runtime does not need these.
func Marshal(s *State) []byte
Next returns the next random value, along with a boolean indicating whether one was available. If one is not available, the caller should call Refill and then repeat the call to Next. Next is //go:nosplit to allow its use in the runtime with per-m data without holding the per-m lock. go:nosplit
func (s *State) Next() (uint64, bool)
Refill refills the state with more random values. After a call to Refill, an immediate call to Next will succeed (unless multiple goroutines are incorrectly sharing a state).
func (s *State) Refill()
Reseed reseeds the state with new random values. After a call to Reseed, any previously returned random values have been erased from the memory of the state and cannot be recovered.
func (s *State) Reseed()
Unmarshal unmarshals the state from a byte slice.
func Unmarshal(s *State, data []byte) error
func _()
block is the chacha8rand block function.
func block(seed *[4]uint64, blocks *[32]uint64, counter uint32)
block_generic is the non-assembly block implementation, for use on systems without special assembly. Even on such systems, it is quite fast: on GOOS=386, ChaCha8 using this code generates random values faster than PCG-DXSM.
func block_generic(seed *[4]uint64, buf *[32]uint64, counter uint32)
qr is the (inlinable) ChaCha8 quarter round.
func qr(a uint32, b uint32, c uint32, d uint32) (_a uint32, _b uint32, _c uint32, _d uint32)
setup sets up 4 ChaCha8 blocks in b32 with the counter and seed. Note that b32 is [16][4]uint32 not [4][16]uint32: the blocks are interlaced the same way they would be in a 4-way SIMD implementations.
func setup(seed *[4]uint64, b32 *[16][4]uint32, counter uint32)
Generated with Arrow