https://github.com/zeroboo/randomselector
Randomly select objects in golang
https://github.com/zeroboo/randomselector
Last synced: 8 months ago
JSON representation
Randomly select objects in golang
- Host: GitHub
- URL: https://github.com/zeroboo/randomselector
- Owner: zeroboo
- License: mit
- Created: 2022-11-09T08:30:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-08T10:36:31.000Z (about 1 year ago)
- Last Synced: 2025-05-08T01:12:31.746Z (8 months ago)
- Language: Go
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# randomselector
Randomly select objects in golang
Current version: v1.0.0
Features:
- Randomly select objects
- Randomly select objects with weights
## Install
```console
go get github.com/zeroboo/randomselector
```
## Usage
```golang
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)
}