diff --git a/domain/model/group_m/group_im.go b/domain/model/group_m/group_im.go index 6177cf324fbc13b6fef726256056cdc11040c931..8b9ecdc86d2f179795a99e23576950e8a36119ab 100644 --- a/domain/model/group_m/group_im.go +++ b/domain/model/group_m/group_im.go @@ -36,6 +36,12 @@ func GetRandomImProvider(model *domain.Model) group_e.GroupProvider { model.Log.Errorf("GetRandomImProvider err:%v", err) return res } + conf := GetRandomGroupImConf(confList) + return conf.Provider +} + +func GetRandomGroupImConf(confList []*GroupIm) *GroupIm { + var res *GroupIm var max int for i, v := range confList { if v.Prob > 0 { @@ -48,7 +54,7 @@ func GetRandomImProvider(model *domain.Model) group_e.GroupProvider { randNum := rand.Intn(max) for _, v := range confList { if v.StartIdx <= randNum && randNum < v.EndIdx { - res = v.Provider + res = v } } return res diff --git a/test/group_power_test.go b/test/group_power_test.go index 54c80d0df956ebe0180fa5d4daf5f59a4f2d0cbb..70b19f2cabc0c47fe06539c8b743a7fcf967bf75 100644 --- a/test/group_power_test.go +++ b/test/group_power_test.go @@ -49,3 +49,23 @@ func TestDoCalcGroupPowerMonthRankActbufa(t *testing.T) { beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02") _ = group_power_s.BufaDoCalcGroupPowerMonthRankAct(domain.CreateModelNil(), calcMonth, beginDate, endDate, starDate) } + +func TestGetRandomImProvider(t *testing.T) { + var times0, times1 int + model := domain.CreateModelNil() + confList, err := group_m.GetGroupImConf(model) + if err != nil { + model.Log.Errorf("GetRandomImProvider err:%v", err) + return + } + for i := 0; i < 1000000; i++ { + conf := group_m.GetRandomGroupImConf(confList) + if conf.Provider == 0 { + times0 += 1 + } else if conf.Provider == 1 { + times1 += 1 + } + } + fmt.Printf("true--------------times0:%v\n", times0) + fmt.Printf("true--------------times1:%v\n", times1) +}