diff --git a/pages/api/tool.ts b/pages/api/tool.ts index 9c85632..b1b923d 100644 --- a/pages/api/tool.ts +++ b/pages/api/tool.ts @@ -78,8 +78,11 @@ export default async function handler( counts[smallestIndex][user][smallestIndex], ]); } - weightList.sort((a, b) => a[1] - b[1] || a[2] - b[2]); - // console.log("weightList", weightList); + // 相同工时数量、相同权重的情况下随机选择 + weightList.sort( + (a, b) => a[1] - b[1] || b[2] - a[2] || Math.random() - 0.5 + ); + console.log("weightList", smallestIndex, weightList); const theChoosenUser = weightList[0][0]; // console.log("theChoosenUser", theChoosenUser); // 记录结果