Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForkRandomProvider ¶
ForkRandomProvider creates a child random provider from the current random provider by using its random data as a seed. This can be leveraged to help increase determinism so multiple go routines can use their own random provider derived from an original. Returns the forked child random provider.
Types ¶
type WeightedRandomChoice ¶
type WeightedRandomChoice[T any] struct { // Data describes the wrapped data that a WeightedRandomChooser should return when making a random WeightedRandomChoice selection. Data T // contains filtered or unexported fields }
WeightedRandomChoice describes a weighted, randomly selectable object for use with a WeightedRandomChooser.
func NewWeightedRandomChoice ¶
func NewWeightedRandomChoice[T any](data T, weight *big.Int) *WeightedRandomChoice[T]
NewWeightedRandomChoice creates a WeightedRandomChoice with the given underlying data and weight to use when added to a WeightedRandomChooser.
type WeightedRandomChooser ¶
type WeightedRandomChooser[T any] struct { // contains filtered or unexported fields }
WeightedRandomChooser takes a series of WeightedRandomChoice objects which wrap underlying data, and returns one of the weighted options randomly.
func NewWeightedRandomChooser ¶
func NewWeightedRandomChooser[T any]() *WeightedRandomChooser[T]
NewWeightedRandomChooser creates a WeightedRandomChooser with a new random provider and mutex lock.
func NewWeightedRandomChooserWithRand ¶
func NewWeightedRandomChooserWithRand[T any](randomProvider *rand.Rand, randomProviderLock *sync.Mutex) *WeightedRandomChooser[T]
NewWeightedRandomChooserWithRand creates a WeightedRandomChooser with the provided random provider and mutex lock to be acquired when using it.
func (*WeightedRandomChooser[T]) AddChoices ¶
func (c *WeightedRandomChooser[T]) AddChoices(choices ...*WeightedRandomChoice[T])
AddChoices adds weighted choices to the WeightedRandomChooser, allowing for future random selection.
func (*WeightedRandomChooser[T]) ChoiceCount ¶
func (c *WeightedRandomChooser[T]) ChoiceCount() int
ChoiceCount returns the count of choices added to this provider.
func (*WeightedRandomChooser[T]) Choose ¶
func (c *WeightedRandomChooser[T]) Choose() (*T, error)
Choose selects a random weighted item from the WeightedRandomChooser, or returns an error if one occurs.