{"slug":"dai-dien-phap-la-gi-thuat-toan-boi-kinh-dich-co-dai-50-thanh-thi","title":"Đại Diễn Pháp Là Gì — Thuật Toán Bói Kinh Dịch Cổ Đại Với 50 Thẻ Thi","summary":"Đại Diễn Pháp (大衍法) là gì? Phương pháp bói Kinh Dịch cổ đại 3000 năm với 50 thẻ thi: nguồn gốc, triết học vũ trụ, quy trình 18 bước, xác suất, và triển khai Python/JS/C.","excerpt":"Đại Diễn Pháp (大衍法) là gì? Phương pháp bói Kinh Dịch cổ đại 3000 năm với 50 thẻ thi: nguồn gốc, triết học vũ trụ, quy trình 18 bước, xác suất, và triển khai Python/JS/C.","markdown":"# Đại Diễn Pháp (大衍法) — Yarrow Stalk Oracle\n## 1. Nguồn Gốc\nĐại Diễn Pháp (大衍法, Dà Yǎn Fǎ) là phương pháp bói Kinh Dịch cổ xưa nhất còn tồn tại, được mô tả trong chương Hệ Từ Truyện (繫辭傳 Xìcí Zhuàn) — phần phụ lục triết học của Kinh Dịch, có niên đại khoảng 300-200 TCN (Chiến Quốc).\n\nNguyên văn cổ:\n\n大衍之數五十，其用四十有九。\nDà yǎn zhī shù wǔshí, qí yòng sìshí yǒu jiǔ.\n\n\"Số đại diễn là năm mươi, sử dụng bốn mươi chín.\"\n\n分而為二以象兩，掛一以象三，揲之以四以象四時，\n歸奇於扐以象閏。五歲再閏，故再扐而後掛。\n\nFēn ér wéi èr yǐ xiàng liǎng, guà yī yǐ xiàng sān,\nshé zhī yǐ sì yǐ xiàng sì shí,\nguī qí yú lè yǐ xiàng rùn.\nWǔ suì zài rùn, gù zài lè ér hòu guà.\n## 2. Ý Nghĩa Triết Học\nMỗi bước trong Đại Diễn Pháp đều mang tượng trưng vũ trụ luận:\n\n50 thẻ = Số Đại Diễn — con số bao trùm vạn vật\n1 thẻ bỏ ra = Thái Cực (太極) — nguồn gốc chưa phân chia, không sử dụng\n49 thẻ sử dụng = Số của Dụng — vạn vật từ Thái Cực sinh ra\nChia 2 nhóm = Lưỡng Nghi (兩儀) — Âm-Dương, Trời-Đất\nRút 1 thẻ = Tam Tài (三才) — Trời-Đất-Người\nĐếm theo 4 = Tứ Thời (四時) — 4 mùa Xuân-Hạ-Thu-Đông\nPhần dư = Nhuận (閏) — tháng nhuận trong lịch âm\n## 3. Quy Trình 18 Bước (3 Biến × 6 Hào)\nMỗi quẻ Kinh Dịch có 6 hào. Mỗi hào cần 3 lần \"biến\" (操作, thao tác). Tổng cộng: 6 hào × 3 biến = 18 bước.\n\n### 3.1. Một Biến (1 iteration):\nBắt đầu với N thẻ thi (lần đầu: 49; các lần sau: số còn lại)\nChia ngẫu nhiên thành 2 nhóm (Tả 左 và Hữu 右)\nRút 1 thẻ từ nhóm Hữu, kẹp vào ngón tay út (tượng Tam Tài)\nĐếm nhóm Tả theo từng 4 thẻ, giữ phần dư (1-4 thẻ)\nĐếm nhóm Hữu theo từng 4 thẻ, giữ phần dư (1-4 thẻ)\nTổng phần dư (1 thẻ kẹp + dư Tả + dư Hữu) = thẻ bỏ ra lần này\n### 3.2. Giá trị phần dư mỗi biến:\nBiến 1: Tổng dư = 5 hoặc 9 (chỉ có 2 giá trị khả dĩ)\n\nBiến 2: Tổng dư = 4 hoặc 8\n\nBiến 3: Tổng dư = 4 hoặc 8\n\n### 3.3. Xác định hào:\nSau 3 biến, tổng thẻ bỏ ra ∈ {13, 17, 21, 25}. Thẻ còn lại chia 4:\n\n36 ÷ 4 = 9 → Thái Dương (老陽 Lão dương) — Dương động, giá trị 9\n32 ÷ 4 = 8 → Thiếu Âm (少陰 Thiếu âm) — Âm tĩnh, giá trị 8\n28 ÷ 4 = 7 → Thiếu Dương (少陽 Thiếu dương) — Dương tĩnh, giá trị 7\n24 ÷ 4 = 6 → Thái Âm (老陰 Lão âm) — Âm động, giá trị 6\n## 4. Xác Suất — Không Cân Bằng\nKhác với gieo 3 đồng xu (xác suất đều 1/8 cho mỗi tổ hợp), Đại Diễn Pháp có xác suất KHÔNG đều:\n\n# Xác suất Đại Diễn Pháp (tính toán chính xác)\n# Biến 1: P(5) = 4/49,  P(9) = 45/49  → gần như chắc chắn ra 9\n# ...nhưng kết quả cuối cùng:\n\nprobs = {\n6: 1/16,    # Thái Âm  (lão âm)   — 6.25%\n7: 5/16,    # Thiếu Dương          — 31.25%\n8: 7/16,    # Thiếu Âm             — 43.75%\n9: 3/16,    # Thái Dương (lão dương) — 18.75%\n}\n\n# So sánh với 3 đồng xu:\ncoin_probs = {\n6: 1/8,     # Thái Âm   — 12.5%\n7: 3/8,     # Thiếu Dương — 37.5%\n8: 3/8,     # Thiếu Âm   — 37.5%\n9: 1/8,     # Thái Dương — 12.5%\n}\n\n# Đại Diễn Pháp thiên về Âm (8) hơn Dương (7)\n# → phản ánh triết lý: Âm (vạn vật) nhiều hơn Dương (trời)\n## 5. Triển Khai Thuật Toán\n### 5.1. Python\nimport random\n\ndef yarrow_one_change(n_stalks):\n\"\"\"Thực hiện 1 biến (thao tác) Đại Diễn Pháp.\n\nArgs:\nn_stalks: Số thẻ hiện có (49 cho biến 1, ít hơn cho biến 2, 3)\nReturns:\nSố thẻ bỏ ra (phần dư)\n\"\"\"\n# Chia ngẫu nhiên thành 2 nhóm\nleft = random.randint(1, n_stalks - 1)\nright = n_stalks - left\n\n# Rút 1 từ nhóm phải (Tam Tài)\nright -= 1\nhand = 1\n\n# Đếm nhóm trái theo 4\nleft_remainder = left % 4\nif left_remainder == 0:\nleft_remainder = 4\n\n# Đếm nhóm phải theo 4\nright_remainder = right % 4\nif right_remainder == 0:\nright_remainder = 4\n\nreturn hand + left_remainder + right_remainder\n\n\ndef yarrow_one_line():\n\"\"\"Tạo 1 hào bằng Đại Diễn Pháp (3 biến).\n\nReturns:\n6 (Thái Âm), 7 (Thiếu Dương), 8 (Thiếu Âm), hoặc 9 (Thái Dương)\n\"\"\"\nstalks = 49\ntotal_removed = 0\n\nfor _ in range(3):  # 3 biến\nremoved = yarrow_one_change(stalks)\ntotal_removed += removed\nstalks -= removed\n\n# Thẻ còn lại chia 4 → giá trị hào\nreturn stalks // 4\n\n\ndef yarrow_hexagram():\n\"\"\"Tạo 1 quẻ 6 hào bằng Đại Diễn Pháp.\n\nReturns:\nList 6 giá trị [hào 1 (dưới), ..., hào 6 (trên)]\n\"\"\"\nreturn [yarrow_one_line() for _ in range(6)]\n\n\n# Sử dụng\nhexagram = yarrow_hexagram()\nprint(f\"Quẻ: {hexagram}\")\nfor i, line in enumerate(hexagram, 1):\nnames = {6: \"Thái Âm ⚋⚋\", 7: \"Thiếu Dương ⚊\", 8: \"Thiếu Âm ⚋\", 9: \"Thái Dương ⚊⚊\"}\nprint(f\"  Hào {i}: {line} — {names[line]}\")\n### 5.2. JavaScript\n/**\n* Đại Diễn Pháp (Yarrow Stalk Method)\n* Thuật toán bói Kinh Dịch cổ đại\n*/\nfunction yarrowOneChange(nStalks) {\nconst left = Math.floor(Math.random() * (nStalks - 1)) + 1;\nlet right = nStalks - left - 1; // -1 cho thẻ Tam Tài\n\nlet leftRem = left % 4 || 4;\nlet rightRem = right % 4 || 4;\n\nreturn 1 + leftRem + rightRem; // hand + left + right\n}\n\nfunction yarrowOneLine() {\nlet stalks = 49;\nfor (let i = 0; i < 3; i++) {\nstalks -= yarrowOneChange(stalks);\n}\nreturn stalks / 4; // 6, 7, 8, or 9\n}\n\nfunction yarrowHexagram() {\nreturn Array.from({ length: 6 }, () => yarrowOneLine());\n}\n\n// Sử dụng\nconst hexagram = yarrowHexagram();\nconsole.log(\"Quẻ:\", hexagram);\n### 5.3. C\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n\nint yarrow_one_change(int n_stalks) {\nint left = 1 + rand() % (n_stalks - 1);\nint right = n_stalks - left - 1;\nint left_rem = left % 4;\nif (left_rem == 0) left_rem = 4;\nint right_rem = right % 4;\nif (right_rem == 0) right_rem = 4;\nreturn 1 + left_rem + right_rem;\n}\n\nint yarrow_one_line(void) {\nint stalks = 49;\nfor (int i = 0; i < 3; i++)\nstalks -= yarrow_one_change(stalks);\nreturn stalks / 4;\n}\n\nint main(void) {\nsrand((unsigned)time(NULL));\nprintf(\"Quẻ Kinh Dịch (Đại Diễn Pháp):\\n\");\nfor (int i = 0; i < 6; i++)\nprintf(\"  Hào %d: %d\\n\", i + 1, yarrow_one_line());\nreturn 0;\n}\n## 6. So Sánh Với Các Phương Pháp Bói Dịch Khác\nĐại Diễn Pháp (蓍草法): 50 cọng thi → 18 bước → xác suất không đều. Chậm nhất nhưng trang trọng nhất\nGieo 3 đồng xu (擲錢法): 3 xu tung → 1 hào. Nhanh, xác suất đều P(6)=P(9)=1/8, P(7)=P(8)=3/8\nPhương pháp Chu Dịch Tiên Sinh: Dùng 6 đồng xu tung 1 lần → 1 quẻ. Nhanh nhất nhưng ít truyền thống\nMai Hoa Dịch Số (梅花易數): Thiệu Ung — dùng số từ thời gian, sự kiện. Không cần công cụ vật lý\n## 7. Đại Diễn Pháp Trong QuizzMan\nTrong hệ thống Kinh Dịch của QuizzMan (lab.quizzman.com), Đại Diễn Pháp được triển khai với:\n\nMô phỏng trực quan: Animation 49 thẻ chia nhóm, đếm, bỏ dư — giúp visualize toàn bộ 18 bước\nEntropy nguồn: Dùng CSPRNG (crypto.getRandomValues) thay vì Math.random() — đảm bảo tính ngẫu nhiên thật sự\nKiểm chứng xác suất: Sau 1 triệu lần chạy, phân phối khớp với lý thuyết (6.25%, 31.25%, 43.75%, 18.75%)\nSo sánh song song: Cùng 1 câu hỏi, xem kết quả từ Đại Diễn Pháp vs 3 đồng xu — thấy rõ sự khác biệt phân phối","html":"<h1>Đại Diễn Pháp (大衍法) — Yarrow Stalk Oracle</h1><h2>1. Nguồn Gốc</h2><p>Đại Diễn Pháp (大衍法, Dà Yǎn Fǎ) là phương pháp bói Kinh Dịch cổ xưa nhất còn tồn tại, được mô tả trong chương Hệ Từ Truyện (繫辭傳 Xìcí Zhuàn) — phần phụ lục triết học của Kinh Dịch, có niên đại khoảng 300-200 TCN (Chiến Quốc).</p><p>Nguyên văn cổ:</p><pre><code class=\"language-plaintext\">大衍之數五十，其用四十有九。</code></pre><pre><code class=\"language-plaintext\">Dà yǎn zhī shù wǔshí, qí yòng sìshí yǒu jiǔ.</code></pre><pre><code class=\"language-plaintext\">\"Số đại diễn là năm mươi, sử dụng bốn mươi chín.\"</code></pre><pre><code class=\"language-plaintext\">分而為二以象兩，掛一以象三，揲之以四以象四時，</code></pre><pre><code class=\"language-plaintext\">歸奇於扐以象閏。五歲再閏，故再扐而後掛。</code></pre><pre><code class=\"language-plaintext\">Fēn ér wéi èr yǐ xiàng liǎng, guà yī yǐ xiàng sān,</code></pre><pre><code class=\"language-plaintext\">shé zhī yǐ sì yǐ xiàng sì shí,</code></pre><pre><code class=\"language-plaintext\">guī qí yú lè yǐ xiàng rùn.</code></pre><pre><code class=\"language-plaintext\">Wǔ suì zài rùn, gù zài lè ér hòu guà.</code></pre><h2>2. Ý Nghĩa Triết Học</h2><p>Mỗi bước trong Đại Diễn Pháp đều mang tượng trưng vũ trụ luận:</p><ul><li>50 thẻ = Số Đại Diễn — con số bao trùm vạn vật</li><li>1 thẻ bỏ ra = Thái Cực (太極) — nguồn gốc chưa phân chia, không sử dụng</li><li>49 thẻ sử dụng = Số của Dụng — vạn vật từ Thái Cực sinh ra</li><li>Chia 2 nhóm = Lưỡng Nghi (兩儀) — Âm-Dương, Trời-Đất</li><li>Rút 1 thẻ = Tam Tài (三才) — Trời-Đất-Người</li><li>Đếm theo 4 = Tứ Thời (四時) — 4 mùa Xuân-Hạ-Thu-Đông</li><li>Phần dư = Nhuận (閏) — tháng nhuận trong lịch âm</li><h2>3. Quy Trình 18 Bước (3 Biến × 6 Hào)</h2></ul><p>Mỗi quẻ Kinh Dịch có 6 hào. Mỗi hào cần 3 lần \"biến\" (操作, thao tác). Tổng cộng: 6 hào × 3 biến = 18 bước.</p><h3>3.1. Một Biến (1 iteration):</h3><ol><li>Bắt đầu với N thẻ thi (lần đầu: 49; các lần sau: số còn lại)</li><li>Chia ngẫu nhiên thành 2 nhóm (Tả 左 và Hữu 右)</li><li>Rút 1 thẻ từ nhóm Hữu, kẹp vào ngón tay út (tượng Tam Tài)</li><li>Đếm nhóm Tả theo từng 4 thẻ, giữ phần dư (1-4 thẻ)</li><li>Đếm nhóm Hữu theo từng 4 thẻ, giữ phần dư (1-4 thẻ)</li><li>Tổng phần dư (1 thẻ kẹp + dư Tả + dư Hữu) = thẻ bỏ ra lần này</li><h3>3.2. Giá trị phần dư mỗi biến:</h3></ol><p>Biến 1: Tổng dư = 5 hoặc 9 (chỉ có 2 giá trị khả dĩ)</p><p>Biến 2: Tổng dư = 4 hoặc 8</p><p>Biến 3: Tổng dư = 4 hoặc 8</p><h3>3.3. Xác định hào:</h3><p>Sau 3 biến, tổng thẻ bỏ ra ∈ {13, 17, 21, 25}. Thẻ còn lại chia 4:</p><ul><li>36 ÷ 4 = 9 → Thái Dương (老陽 Lão dương) — Dương động, giá trị 9</li><li>32 ÷ 4 = 8 → Thiếu Âm (少陰 Thiếu âm) — Âm tĩnh, giá trị 8</li><li>28 ÷ 4 = 7 → Thiếu Dương (少陽 Thiếu dương) — Dương tĩnh, giá trị 7</li><li>24 ÷ 4 = 6 → Thái Âm (老陰 Lão âm) — Âm động, giá trị 6</li><h2>4. Xác Suất — Không Cân Bằng</h2></ul><p>Khác với gieo 3 đồng xu (xác suất đều 1/8 cho mỗi tổ hợp), Đại Diễn Pháp có xác suất KHÔNG đều:</p><pre><code class=\"language-python\"># Xác suất Đại Diễn Pháp (tính toán chính xác)</code></pre><pre><code class=\"language-python\"># Biến 1: P(5) = 4/49,  P(9) = 45/49  → gần như chắc chắn ra 9</code></pre><pre><code class=\"language-python\"># ...nhưng kết quả cuối cùng:</code></pre><pre><code class=\"language-python\">probs = {</code></pre><pre><code class=\"language-python\">    6: 1/16,    # Thái Âm  (lão âm)   — 6.25%</code></pre><pre><code class=\"language-python\">    7: 5/16,    # Thiếu Dương          — 31.25%</code></pre><pre><code class=\"language-python\">    8: 7/16,    # Thiếu Âm             — 43.75%</code></pre><pre><code class=\"language-python\">    9: 3/16,    # Thái Dương (lão dương) — 18.75%</code></pre><pre><code class=\"language-python\">}</code></pre><pre><code class=\"language-python\"># So sánh với 3 đồng xu:</code></pre><pre><code class=\"language-python\">coin_probs = {</code></pre><pre><code class=\"language-python\">    6: 1/8,     # Thái Âm   — 12.5%</code></pre><pre><code class=\"language-python\">    7: 3/8,     # Thiếu Dương — 37.5%</code></pre><pre><code class=\"language-python\">    8: 3/8,     # Thiếu Âm   — 37.5%</code></pre><pre><code class=\"language-python\">    9: 1/8,     # Thái Dương — 12.5%</code></pre><pre><code class=\"language-python\">}</code></pre><pre><code class=\"language-python\"># Đại Diễn Pháp thiên về Âm (8) hơn Dương (7)</code></pre><pre><code class=\"language-python\"># → phản ánh triết lý: Âm (vạn vật) nhiều hơn Dương (trời)</code></pre><h2>5. Triển Khai Thuật Toán</h2><h3>5.1. Python</h3><pre><code class=\"language-python\">import random</code></pre><pre><code class=\"language-python\">def yarrow_one_changens​talks:</code></pre><pre><code class=\"language-python\">    \"\"\"Thực hiện 1 biến (thao tác) Đại Diễn Pháp.</code></pre><pre><code class=\"language-python\">    Args:</code></pre><pre><code class=\"language-python\">        n_stalks: Số thẻ hiện có (49 cho biến 1, ít hơn cho biến 2, 3)</code></pre><pre><code class=\"language-python\">    Returns:</code></pre><pre><code class=\"language-python\">        Số thẻ bỏ ra (phần dư)</code></pre><pre><code class=\"language-python\">    \"\"\"</code></pre><pre><code class=\"language-python\">    # Chia ngẫu nhiên thành 2 nhóm</code></pre><pre><code class=\"language-python\">    left = random.randint1,ns​talks−1</code></pre><pre><code class=\"language-python\">    right = n_stalks - left</code></pre><pre><code class=\"language-python\">    # Rút 1 từ nhóm phải (Tam Tài)</code></pre><pre><code class=\"language-python\">    right -= 1</code></pre><pre><code class=\"language-python\">    hand = 1</code></pre><pre><code class=\"language-python\">    # Đếm nhóm trái theo 4</code></pre><pre><code class=\"language-python\">    left_remainder = left % 4</code></pre><pre><code class=\"language-python\">    if left_remainder == 0:</code></pre><pre><code class=\"language-python\">        left_remainder = 4</code></pre><pre><code class=\"language-python\">    # Đếm nhóm phải theo 4</code></pre><pre><code class=\"language-python\">    right_remainder = right % 4</code></pre><pre><code class=\"language-python\">    if right_remainder == 0:</code></pre><pre><code class=\"language-python\">        right_remainder = 4</code></pre><pre><code class=\"language-python\">    return hand + left_remainder + right_remainder</code></pre><pre><code class=\"language-python\">def yarrow_one_line():</code></pre><pre><code class=\"language-python\">    \"\"\"Tạo 1 hào bằng Đại Diễn Pháp (3 biến).</code></pre><pre><code class=\"language-python\">    Returns:</code></pre><pre><code class=\"language-python\">        6 (Thái Âm), 7 (Thiếu Dương), 8 (Thiếu Âm), hoặc 9 (Thái Dương)</code></pre><pre><code class=\"language-python\">    \"\"\"</code></pre><pre><code class=\"language-python\">    stalks = 49</code></pre><pre><code class=\"language-python\">    total_removed = 0</code></pre><pre><code class=\"language-python\">    for _ in range(3):  # 3 biến</code></pre><pre><code class=\"language-python\">        removed = yarrow_one_changestalks</code></pre><pre><code class=\"language-python\">        total_removed += removed</code></pre><pre><code class=\"language-python\">        stalks -= removed</code></pre><pre><code class=\"language-python\">    # Thẻ còn lại chia 4 → giá trị hào</code></pre><pre><code class=\"language-python\">    return stalks // 4</code></pre><pre><code class=\"language-python\">def yarrow_hexagram():</code></pre><pre><code class=\"language-python\">    \"\"\"Tạo 1 quẻ 6 hào bằng Đại Diễn Pháp.</code></pre><pre><code class=\"language-python\">    Returns:</code></pre><pre><code class=\"language-python\">        List 6 giá trị [hào 1 (dưới), ..., hào 6 (trên)]</code></pre><pre><code class=\"language-python\">    \"\"\"</code></pre><pre><code class=\"language-python\">    return [yarrow_one_line() for _ in range(6)]</code></pre><pre><code class=\"language-python\"># Sử dụng</code></pre><pre><code class=\"language-python\">hexagram = yarrow_hexagram()</code></pre><pre><code class=\"language-python\">printf&amp;quot;Quẻ: {hexagram}&amp;quot;</code></pre><pre><code class=\"language-python\">for i, line in enumerate(hexagram, 1):</code></pre><pre><code class=\"language-python\">    names = {6: \"Thái Âm ⚋⚋\", 7: \"Thiếu Dương ⚊\", 8: \"Thiếu Âm ⚋\", 9: \"Thái Dương ⚊⚊\"}</code></pre><pre><code class=\"language-python\">    printf&amp;quot;  Hào {i}: {line} — {names[line]}&amp;quot;</code></pre><h3>5.2. JavaScript</h3><pre><code class=\"language-javascript\">/**</code></pre><pre><code class=\"language-javascript\"> * Đại Diễn Pháp (Yarrow Stalk Method)</code></pre><pre><code class=\"language-javascript\"> * Thuật toán bói Kinh Dịch cổ đại</code></pre><pre><code class=\"language-javascript\"> */</code></pre><pre><code class=\"language-javascript\">function yarrowOneChangenStalks {</code></pre><pre><code class=\"language-javascript\">  const left = Math.floor(Math.random() * (nStalks - 1)) + 1;</code></pre><pre><code class=\"language-javascript\">  let right = nStalks - left - 1; // -1 cho thẻ Tam Tài</code></pre><pre><code class=\"language-javascript\">  let leftRem = left % 4 || 4;</code></pre><pre><code class=\"language-javascript\">  let rightRem = right % 4 || 4;</code></pre><pre><code class=\"language-javascript\">  return 1 + leftRem + rightRem; // hand + left + right</code></pre><pre><code class=\"language-javascript\">}</code></pre><pre><code class=\"language-javascript\">function yarrowOneLine() {</code></pre><pre><code class=\"language-javascript\">  let stalks = 49;</code></pre><pre><code class=\"language-javascript\">  for let i = 0; i &amp;lt; 3; i++ {</code></pre><pre><code class=\"language-javascript\">    stalks -= yarrowOneChangestalks;</code></pre><pre><code class=\"language-javascript\">  }</code></pre><pre><code class=\"language-javascript\">  return stalks / 4; // 6, 7, 8, or 9</code></pre><pre><code class=\"language-javascript\">}</code></pre><pre><code class=\"language-javascript\">function yarrowHexagram() {</code></pre><pre><code class=\"language-javascript\">  return Array.from{ length: 6 }, () =&amp;gt; yarrowOneLine();</code></pre><pre><code class=\"language-javascript\">}</code></pre><pre><code class=\"language-javascript\">// Sử dụng</code></pre><pre><code class=\"language-javascript\">const hexagram = yarrowHexagram();</code></pre><pre><code class=\"language-javascript\">console.log(\"Quẻ:\", hexagram);</code></pre><h3>5.3. C</h3><pre><code class=\"language-c\">#include &lt;stdio.h&gt;</code></pre><pre><code class=\"language-c\">#include &lt;stdlib.h&gt;</code></pre><pre><code class=\"language-c\">#include &lt;time.h&gt;</code></pre><pre><code class=\"language-c\">int yarrow_one_changeintns​talks {</code></pre><pre><code class=\"language-c\">    int left = 1 + rand() % ns​talks−1;</code></pre><pre><code class=\"language-c\">    int right = n_stalks - left - 1;</code></pre><pre><code class=\"language-c\">    int left_rem = left % 4;</code></pre><pre><code class=\"language-c\">    if leftr​em==0 left_rem = 4;</code></pre><pre><code class=\"language-c\">    int right_rem = right % 4;</code></pre><pre><code class=\"language-c\">    if rightr​em==0 right_rem = 4;</code></pre><pre><code class=\"language-c\">    return 1 + left_rem + right_rem;</code></pre><pre><code class=\"language-c\">}</code></pre><pre><code class=\"language-c\">int yarrow_one_linevoid {</code></pre><pre><code class=\"language-c\">    int stalks = 49;</code></pre><pre><code class=\"language-c\">    for int i = 0; i &amp;lt; 3; i++</code></pre><pre><code class=\"language-c\">        stalks -= yarrow_one_changestalks;</code></pre><pre><code class=\"language-c\">    return stalks / 4;</code></pre><pre><code class=\"language-c\">}</code></pre><pre><code class=\"language-c\">int mainvoid {</code></pre><pre><code class=\"language-c\">    srand((unsigned)time(NULL));</code></pre><pre><code class=\"language-c\">    printf&amp;quot;Quẻ Kinh Dịch (Đại Diễn Pháp):\\n&amp;quot;;</code></pre><pre><code class=\"language-c\">    for int i = 0; i &amp;lt; 6; i++</code></pre><pre><code class=\"language-c\">        printf&amp;quot;  Hào %d: %d\\n&amp;quot;, i + 1, yarrow_one_line();</code></pre><pre><code class=\"language-c\">    return 0;</code></pre><pre><code class=\"language-c\">}</code></pre><h2>6. So Sánh Với Các Phương Pháp Bói Dịch Khác</h2><ul><li>Đại Diễn Pháp (蓍草法): 50 cọng thi → 18 bước → xác suất không đều. Chậm nhất nhưng trang trọng nhất</li><li>Gieo 3 đồng xu (擲錢法): 3 xu tung → 1 hào. Nhanh, xác suất đều P(6)=P(9)=1/8, P(7)=P(8)=3/8</li><li>Phương pháp Chu Dịch Tiên Sinh: Dùng 6 đồng xu tung 1 lần → 1 quẻ. Nhanh nhất nhưng ít truyền thống</li><li>Mai Hoa Dịch Số (梅花易數): Thiệu Ung — dùng số từ thời gian, sự kiện. Không cần công cụ vật lý</li><h2>7. Đại Diễn Pháp Trong QuizzMan</h2></ul><p>Trong hệ thống Kinh Dịch của QuizzMan (lab.quizzman.com), Đại Diễn Pháp được triển khai với:</p><ul><li>Mô phỏng trực quan: Animation 49 thẻ chia nhóm, đếm, bỏ dư — giúp visualize toàn bộ 18 bước</li><li>Entropy nguồn: Dùng CSPRNG (crypto.getRandomValues) thay vì Math.random() — đảm bảo tính ngẫu nhiên thật sự</li><li>Kiểm chứng xác suất: Sau 1 triệu lần chạy, phân phối khớp với lý thuyết (6.25%, 31.25%, 43.75%, 18.75%)</li><li>So sánh song song: Cùng 1 câu hỏi, xem kết quả từ Đại Diễn Pháp vs 3 đồng xu — thấy rõ sự khác biệt phân phối</li></ul>","tags":["Kinh Dịch","Lịch sử","Thuật toán","Văn hóa"],"author":"Quản trị viên","publishedAt":"2026-04-04T07:48:11.009Z","updatedAt":"2026-10-13T12:52:09.024Z","published_at":"2026-04-04T07:48:11.009Z","updated_at":"2026-10-13T12:52:09.024Z","view_count":431,"canonical":"https://wiki.quizzman.com/wiki/dai-dien-phap-la-gi-thuat-toan-boi-kinh-dich-co-dai-50-thanh-thi","url":"https://wiki.quizzman.com/wiki/dai-dien-phap-la-gi-thuat-toan-boi-kinh-dich-co-dai-50-thanh-thi","markdownUrl":"https://wiki.quizzman.com/api/articles/dai-dien-phap-la-gi-thuat-toan-boi-kinh-dich-co-dai-50-thanh-thi.md","apiUrl":"https://wiki.quizzman.com/api/articles/dai-dien-phap-la-gi-thuat-toan-boi-kinh-dich-co-dai-50-thanh-thi"}