复杂随机函数

  async getHome() {
      let temp = await http.getHome();
      //随机方法
      function getRandomElements(arr, count) {
        var shuffled = arr.slice(0),
          i = arr.length,
          min = i - count,
          temp,
          index;
        while (i-- > min) {
          index = Math.floor((i + 1) * Math.random());
          temp = shuffled[index];
          shuffled[index] = shuffled[i];
          shuffled[i] = temp;
          // console.log(shuffled[i]);
        }
        return shuffled.slice(min);
      }

      if (temp != null) {
        this.recommend.push(getRandomElements(temp, 1));
      }
      // console.log(this.recommend);
    },
posted @ 2021-05-13 17:29  zjxgdq  阅读(64)  评论(0)    收藏  举报