From 6bfa03f0d1b5ad0257c0a3900e12a165006dec8b Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Tue, 23 May 2023 13:55:03 +0800 Subject: [PATCH] =?UTF-8?q?trtc=E5=AF=BC=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/group_m/group_im.go | 8 +++++++- test/group_power_test.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/domain/model/group_m/group_im.go b/domain/model/group_m/group_im.go index 6177cf3..8b9ecdc 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 54c80d0..70b19f2 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) +} -- 2.22.0