ソースを参照

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
}

読み込み中…
キャンセル
保存