package rands import ( "fmt" "testing" ) func TestWeightedChoice(t *testing.T) { choices := []Choice[int, int]{ {Weight: 10, Item: 300}, {Weight: 1, Item: 100}, {Weight: 5, Item: 200}, } times := make(map[int]int) for range 100000 { c, ok := WeightedChoice(choices) if !ok { t.Error("weight choice error") return } times[c.Item]++ } fmt.Println(times) // map[100:6156 200:31280 300:62564] }