Browse Source

feat: "换用洗牌算法"

Ritchie 1 năm trước cách đây
mục cha
commit
4eb1784e58
9 tập tin đã thay đổi với 18 bổ sung4 xóa
  1. BIN
      2.JPG
  2. BIN
      3.jpg
  3. BIN
      4.JPG
  4. BIN
      5.JPG
  5. BIN
      6.jpg
  6. BIN
      back.jpg
  7. BIN
      back1.jpg
  8. 0 0
      back2.png
  9. 18 4
      index.html

BIN
2.JPG


BIN
3.jpg


BIN
4.JPG


BIN
5.JPG


BIN
6.jpg


BIN
back.jpg


BIN
back1.jpg


back.png → back2.png


+ 18 - 4
index.html

@@ -93,7 +93,7 @@
       .result-container p {
         font-size: 28px;
         font-weight: bold;
-        color: #cf3400;
+        color: #ea4f0d;
         animation: blink 1.5s infinite;
       }
       @keyframes blink {
@@ -206,7 +206,7 @@
 
           if (selectDepartment === "RD") {
             namesInput.value =
-              "张凤兰, 王巧贤, 阮珊珊, 谢焕婷, 李婕妤, 李广, 高旭坤, 刘云, 邓远锋, 吴宗澍, 曾文龙, 黄彦, 刘银华, 肖夜华, 严成发, 文孔燊, 洪序滨, 江锦文, 张乐瑶, 张镜明, 陈智雄, 陈珍旭, 王莞琳, 王和富, 王则钰, 王杰, 蔡文怡";
+              "张凤兰, 王巧贤, 阮珊珊, 谢焕婷, 李婕妤, 李广, 高旭坤, 刘云, 邓远锋, 吴宗澍, 曾文龙, 黄彦, 刘银华, 肖夜华, 严成发, 文孔燊, 洪序滨, 江锦文, 张乐瑶, 张镜明, 陈智雄, 陈珍旭, 王莞琳, 王和富, 王则钰, 王杰, 蔡文怡, 陈智慧, 邓诗敏";
           } else if (selectDepartment === "PD") {
             namesInput.value = "张三, 李四, 王五";
           } else if (selectDepartment === "MD") {
@@ -215,16 +215,30 @@
         });
 
       function selectRandomName(namesArray, excludedNamesArray) {
+        // 过滤被排除的人名
         var filteredNames = filterNames(namesArray, excludedNamesArray);
         if (filteredNames.length === 0) {
           document.getElementById("randomName").innerHTML = "没有可抽取的人名";
           return;
         }
 
+        // 使用洗牌算法对过滤后的人名数组进行随机排序
+        for (var i = filteredNames.length - 1; i > 0; i--) {
+          var j = Math.floor(Math.random() * (i + 1));
+          var temp = filteredNames[i];
+          filteredNames[i] = filteredNames[j];
+          filteredNames[j] = temp;
+        }
+
+        var currentIndex = 0;
         var interval = setInterval(function () {
-          var randomIndex = Math.floor(Math.random() * filteredNames.length);
+          // var randomIndex = Math.floor(Math.random() * filteredNames.length);
           document.getElementById("randomName").innerHTML =
-            "是(¬‿¬): " + filteredNames[randomIndex] + " ?";
+            "是(¬‿¬): " + filteredNames[currentIndex] + " ?";
+            currentIndex++;
+            if (currentIndex === filteredNames.length) {
+              clearInterval(interval);
+            }
         }, 400);
 
         setTimeout(() => {