diff --git a/rule/public_platoon_relate_commission.go b/rule/public_platoon_relate_commission.go index d6cf847..8fa0ca1 100644 --- a/rule/public_platoon_relate_commission.go +++ b/rule/public_platoon_relate_commission.go @@ -533,7 +533,7 @@ func FindRandUser(engine *xorm.Engine, nums int) (resp []int64, err error) { var uniqueMap = map[int64]bool{} var j = 0 for { - ids := randSeedInt(int64(minM.Id), int64(maxM.Id), nums-len(resp), uniqueMap) + ids := randSeedInt(int64(minM.Id), int64(maxM.Id), nums-len(resp), uniqueMap, &[]int64{}) var list []model.UserPublicPlatoonRelation if err1 := engine.In("id", ids). Find(&list); err1 != nil { @@ -559,19 +559,20 @@ func FindRandUser(engine *xorm.Engine, nums int) (resp []int64, err error) { return } -func randSeedInt(start, end int64, nums int, uniqueMap map[int64]bool) (resp []int64) { +func randSeedInt(start, end int64, nums int, uniqueMap map[int64]bool, resp *[]int64) (res []int64) { rand.Seed(time.Now().UnixNano()) for { result := rand.Int63n(end) + start if !uniqueMap[result] { - resp = append(resp, result) + *resp = append(*resp, result) uniqueMap[result] = true break } } - if len(resp) < nums { - randSeedInt(start, end, nums, uniqueMap) + if len(*resp) < nums { + randSeedInt(start, end, nums, uniqueMap, resp) } - return + res = *resp + return res }