weighted

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*drawOptions)

func WithRand

func WithRand(r Roller) Option

type Roller

type Roller func(int) int

type Selector

type Selector[T comparable] struct {
	// contains filtered or unexported fields
}

func New

func New[T comparable]() *Selector[T]

New creates a new weighted selector

func (*Selector[T]) Add

func (l *Selector[T]) Add(ID T, weight int)

Add adds an item for weighted selection

func (*Selector[T]) Draw

func (l *Selector[T]) Draw(opts ...Option) T

Draw selects an item by weight (supports Option pattern)

func (*Selector[T]) Items

func (l *Selector[T]) Items() map[T]int

func (*Selector[T]) Len

func (l *Selector[T]) Len() int

Len get amount of items

func (*Selector[T]) Weight

func (l *Selector[T]) Weight() int

Weight get total weight of items

Jump to

Keyboard shortcuts

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