瀏覽代碼

update

master
DengBiao 11 月之前
父節點
當前提交
61e5516cbe
共有 1 個文件被更改,包括 7 次插入6 次删除
  1. +7
    -6
      rule/public_platoon_relate_commission.go

+ 7
- 6
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
}

Loading…
取消
儲存