Documentation ¶
Overview ¶
Package roundrobinrandom implements a randomized round-based ordering type.
Each element in an Order is visited in random sequence, once per round (possibly excluding the round it is added to the Order). Therefore, in an Order of n elements, successive visits to the same element will occur at intervals of at most 2n-1 calls to Next.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Order ¶
type Order[T comparable] struct { // contains filtered or unexported fields }
An Order holds values to return in a randomized round-based sequence such that each value is returned once per round. The sequence is shuffled after each round. The zero value of type Order is an empty Order ready for use.
func (*Order[T]) Add ¶
func (o *Order[T]) Add(t T)
Add inserts t into a random position in the Order. Depending on where it is inserted, t may or may not be returned in the current round.
func (*Order[T]) IndependentSample ¶
IndependentSample returns a slice of unique elements besides exclude, chosen at random. If there are at least n such elements, IndependentSample returns n of them, or else all of them.