From fdee933ca4bb35df53c4f72340c8773fe952c35c Mon Sep 17 00:00:00 2001 From: shanmite Date: Thu, 29 Jul 2021 22:38:32 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E5=AF=B9=E5=B0=86=E8=A6=81=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=8A=A8=E6=80=81=E6=B4=97=E7=89=8C=E4=B9=B1?= =?UTF-8?q?=E5=BA=8F=20=E9=98=B2=E6=AD=A2=E8=A2=AB=E7=9C=8B=E5=87=BA?= =?UTF-8?q?=E6=98=AF=E6=8A=BD=E5=A5=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Monitor.js | 2 +- lib/Util.js | 18 ++++++++++++++++++ main.js | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Monitor.js b/lib/Monitor.js index f57fa78..d78ead0 100644 --- a/lib/Monitor.js +++ b/lib/Monitor.js @@ -89,7 +89,7 @@ class Monitor extends Public { log.info('筛选动态', `筛选完毕(${len})`); if (len) { - for (const Lottery of allLottery) { + for (const Lottery of Util.shuffle(allLottery)) { let status = 0; if (Lottery.isOfficialLottery) { let { ts } = await BiliAPI.getLotteryNotice(Lottery.dyid); diff --git a/lib/Util.js b/lib/Util.js index 419814c..f1f2183 100644 --- a/lib/Util.js +++ b/lib/Util.js @@ -115,6 +115,24 @@ const Util = { } return RandomOne }, + /** + * Fisher–Yates shuffle洗牌 + * @template T + * @param {Array} array + * @return {Array} + */ + shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; + }, + /** + * 是否有指定环境变量 + * @param {string} env_name + * @returns + */ hasEnv(env_name) { return process.env[env_name] ? true : false; }, diff --git a/main.js b/main.js index bbee2bc..210547b 100644 --- a/main.js +++ b/main.js @@ -10,7 +10,7 @@ const metainfo = [ ` __/ | | | `, ` |___/ |_| `, ` `, - ` v1.9.9 by shanmite`, + ` v2.0.0 by shanmite`, ] /**多账号存储 */ let multiple_account = [];