func Marshal(s *State) []byte
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 Unmarshal(s *State, data []byte) error
Unmarshal unmarshals the state from a byte slice.
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 {
// contains filtered or unexported fields
}
func (s *State) Init(seed [32]byte)
Init seeds the State with the given seed value.
func (s *State) Init64(seed [4]uint64)
Init64 seeds the state with the given seed value.
func (s *State) Next() (uint64, bool)
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.
func (s *State) Refill()
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) Reseed()
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.