picker

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 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 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) 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.

Jump to

Keyboard shortcuts

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