package xrand import ( "github.com/stretchr/testify/assert" "testing" ) func TestWeightRandom(t *testing.T) { stat := make(map[any]int) for i := 1; i <= 10000; i++ { items := map[uint]string{ 5: "a", 15: "b", 30: "c", 50: "d", } item, err := WeightRandom(items) assert.Nil(t, err) if _, ok := stat[item]; !ok { stat[item] = 0 } stat[item]++ } t.Log(stat) }