picker

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Picker

type Picker struct {
	// contains filtered or unexported fields
}

Picker is a utility class for picking values from a list using weighted random selection. The weight is based on a user-defined score function, where low scores are exponentially more favorable than high scores.

func Make

func Make(values []interface{}, scoreFn func(interface{}) float64) Picker

Make creates a Picker with the given values and score function.

func (Picker) Disable

func (p Picker) Disable(index uint)

Disable semi-permanently alters the probability of selecting the index'th value to 0.

func (Picker) Divvy

func (p Picker) Divvy(amount float64) []float64

Divvy divides and distributes the given quantity among the values according to their individual probabilities.

func (Picker) Enable added in v0.6.1

func (p Picker) Enable(index uint)

Enable undoes the effect of a previous call to Disable.

func (Picker) Get

func (p Picker) Get(index uint) interface{}

Get returns the index'th value in this Picker, using 0-based indexing.

func (Picker) Len

func (p Picker) Len() uint

Len returns the number of values in this Picker.

func (Picker) Pick

func (p Picker) Pick(rng *rand.Rand) uint

Pick randomly selects the index of a value.

func (Picker) Worst added in v0.6.1

func (p Picker) Worst() (uint, bool)

Worst deterministically picks the index of the value with the worst score. Disabled values are ignored.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL