redundance.go 864 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "math/rand"
  4. "time"
  5. "go-common/app/interface/bbq/app-bbq/model"
  6. )
  7. // GetRandVideoList .
  8. func (d *Dao) GetRandVideoList(mid int64, limit int) []*model.SvInfo {
  9. var result []*model.SvInfo
  10. r := rand.New(rand.NewSource(time.Now().Unix()))
  11. mask := len(d.redundanceVideos) - limit
  12. cursor := r.Int() % mask
  13. for _, v := range d.redundanceVideos[cursor : cursor+limit] {
  14. result = append(result, &model.SvInfo{
  15. SVID: v.Svid,
  16. AVID: v.Avid,
  17. CID: v.Cid,
  18. MID: mid,
  19. })
  20. }
  21. return result
  22. }
  23. // GetRandSvList .
  24. func (d *Dao) GetRandSvList(limit int) []int64 {
  25. result := make([]int64, limit)
  26. r := rand.New(rand.NewSource(time.Now().Unix()))
  27. mask := len(d.redundanceVideos) - limit
  28. cursor := r.Int() % mask
  29. for _, v := range d.redundanceVideos[cursor : cursor+limit] {
  30. result = append(result, v.Svid)
  31. }
  32. return result
  33. }