modulepackage
1.0.8
Repository: https://github.com/zeroboo/randomselector.git
Documentation: pkg.go.dev
# README
randomselector
Randomly select objects in golang Current version: v1.0.0 Features:
- Randomly select objects
- Randomly select objects with weights
Install
go get github.com/zeroboo/randomselector
Usage
package main
import (
"fmt"
"github.com/zeroboo/randomselector"
)
func main() {
//Select values randomly with equally rate for each value, 1/3 chance for each value
value, errSelect := randomselector.SelectValues("1", "2", "3")
fmt.Println("Select values: ", value, errSelect)
//Select one of 2 string: "hello", "world" with equal rate (50% chance for each)
weightValue, errSelect := randomselector.SelectWithWeight(
randomselector.WeightValue{Value: "1", Weight: 1},
randomselector.WeightValue{Value: "2", Weight: 1},
)
fmt.Println("Select weight value: ", weightValue, errSelect)
}
# Functions
No description provided by the author
Selects values randomly with equally rate for each value
Return: - selected value if selecting is successful - error if any, nil if selecting is successful.
Randomly selects one of weighted values
Return: - selected value - error if any, nil if selecting is successful.
# Structs
No description provided by the author