selector

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package selector implements weighted random selection algorithm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sequential

type Sequential[T any] struct {
	// contains filtered or unexported fields
}

Sequential acts like a queue and picks elements one-by-one starting from the first element.

func NewSequentialSelector

func NewSequentialSelector[T any](values []T) *Sequential[T]

NewSequentialSelector initializes a Sequential selector with default starting index 0.

func (*Sequential[T]) Pick

func (s *Sequential[T]) Pick() T

Pick returns the next available element from the values array if one exists. Returns the zero value of type T otherwise.

type WeightedRand

type WeightedRand[T any] struct {
	// contains filtered or unexported fields
}

WeightedRand picks elements randomly based on their weights. It uses math/rand/v2 global functions which are safe for concurrent use.

func NewWeightedRandSelector

func NewWeightedRandSelector[T any](values []T, weights []int) *WeightedRand[T]

NewWeightedRandSelector initializes a WeightedRand by copying source values and calculating total weight.

func (*WeightedRand[T]) Pick

func (wrs *WeightedRand[T]) Pick() T

Pick returns a randomly chosen element from values based on its weight, if any exists.

Jump to

Keyboard shortcuts

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