{"id":574,"date":"2023-05-17T13:56:31","date_gmt":"2023-05-17T05:56:31","guid":{"rendered":"https:\/\/www.db2go.net\/?p=574"},"modified":"2023-05-17T13:59:09","modified_gmt":"2023-05-17T05:59:09","slug":"%e6%a0%b9%e6%8d%ae%e5%ae%98%e6%96%b9%e7%bb%99%e5%87%ba%e7%9a%84%e7%8a%b6%e5%85%83%e7%ad%be%e6%a6%82%e7%8e%87%e6%a8%a1%e6%8b%9fnba%e9%80%89%e7%a7%80%e9%a1%ba%e4%bd%8d","status":"publish","type":"post","link":"https:\/\/www.db2go.net\/?p=574","title":{"rendered":"\u6839\u636e\u5b98\u65b9\u7ed9\u51fa\u7684\u72b6\u5143\u7b7e\u6982\u7387\u6a21\u62dfNBA\u9009\u79c0\u987a\u4f4d"},"content":{"rendered":"<p>\u9996\u5148\u606d\u559c\u9a6c\u523a\u961f\u62bd\u4e2d\u4e86\u72b6\u5143\u7b7e\uff0c\u8fd9\u4e0b\u6587\u73ed\u4e9a\u9a6c\u8dd1\u4e0d\u8131\u4e86\u3002\u672a\u6765\u90fd\u662f\u4ed6\u4eec\u7684\u3002<\/p>\n<p>\u5bf9\u8fd9\u4e2a\u9009\u79c0\u987a\u5e8f\u7a81\u7136\u6709\u70b9\u5174\u8da3\uff0c\u60f3\u60f3\u5e94\u8be5\u600e\u4e48\u53bb\u5b9e\u73b0\u5b83\u3002\u6839\u636e\u5b98\u65b9\u7ed9\u51fa\u7684\u72b6\u5143\u7b7e\u6982\u7387\u6a21\u62dfNBA\u9009\u79c0\u987a\u4f4d\u7684\u601d\u8def\u662f\uff1a\u9996\u5148\u5b9a\u4e49\u4e86\u4e00\u4e2aTeam\u7ed3\u6784\u4f53\uff0c\u5305\u542b\u4e86\u7403\u961f\u7684\u540d\u79f0\u548c\u62bd\u4e2d\u72b6\u5143\u7b7e\u7684\u6982\u7387\u3002\u6ce8\u610f\u8fd9\u91cc\u6211\u4eec\u5c06\u6982\u7387\u6269\u5927\u4e86100\u500d\uff0c\u53d8\u6210\u4e86\u6574\u6570\uff0c\u4fbf\u4e8e\u8ba1\u7b97\u3002\u63a5\u7740\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u968f\u673a\u6570\u751f\u6210\u5668\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e24\u4e2a\u6570\u7ec4\uff1a\u4e00\u4e2a\u4ee3\u8868\u7403\u961f\uff0c\u4e00\u4e2a\u4ee3\u8868\u5bf9\u5e94\u7684\u62bd\u7b7e\u6982\u7387\u3002\u7136\u540e\u751f\u6210\u4e00\u4e2a\u8303\u56f4\u5728[0, sumProbs)\u7684\u968f\u673a\u6570\uff0c\u4f9d\u6b21\u51cf\u53bb\u6bcf\u4e2a\u7403\u961f\u7684\u62bd\u7b7e\u6982\u7387\uff0c\u5f53\u7ed3\u679c\u5c0f\u4e8e0\u65f6\uff0c\u5bf9\u5e94\u7684\u7403\u961f\u5c31\u88ab\u62bd\u4e2d\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6bcf\u4e2a\u7403\u961f\u88ab\u62bd\u4e2d\u7684\u6982\u7387\u4e0e\u5176\u62bd\u7b7e\u6982\u7387\u4e00\u81f4\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u91cc\u7684\u6982\u7387\u662f\u6574\u6570\uff0c\u6240\u4ee5\u5982\u679c\u6982\u7387\u662f\u5c0f\u6570\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u6574\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6982\u7387\u662f0.14\uff0c\u53ef\u4ee5\u5c06\u6240\u6709\u7684\u6982\u7387\u4e58\u4ee5100\uff0c\u8f6c\u6362\u4e3a\u6574\u657014\u3002<\/p>\n<pre><code class=\"language-go line-numbers\">package main\n\nimport (\n    \"fmt\"\n    \"math\/rand\"\n    \"time\"\n)\n\ntype Team struct {\n    name string\n    prob int\n}\n\nfunc remove(slice []*Team, i int) []*Team {\n    return append(slice[:i], slice[i+1:]...)\n}\n\nfunc weightedRandom(teams []*Team) (picked *Team, rest []*Team) {\n    var total int\n    for _, t := range teams {\n        total += t.prob\n    }\n\n    rand.Seed(time.Now().UnixNano())\n    r := rand.Intn(total)\n\n    for i, t := range teams {\n        r -= t.prob\n        if r &lt; 0 {\n            return t, remove(teams, i)\n        }\n    }\n\n    return teams[0], remove(teams, 0)\n}\n\nfunc main() {\n    teams := []*Team{\n        {\"\u6d3b\u585e\", 1400},\n        {\"\u706b\u7bad\", 1400},\n        {\"\u9a6c\u523a\", 1400},\n        {\"\u9ec4\u8702\", 1250},\n        {\"\u5f00\u62d3\u8005\", 1050},\n        {\"\u9b54\u672f\", 900},\n        {\"\u6b65\u884c\u8005\", 680},\n        {\"\u5947\u624d\", 670},\n        {\"\u7235\u58eb\", 450},\n        {\"\u72ec\u884c\u4fa0\", 300},\n        {\"\u516c\u725b\", 180},\n        {\"\u96f7\u9706\", 170},\n        {\"\u731b\u9f99\", 100},\n        {\"\u9e48\u9e55\", 50},\n        \/\/\u5176\u4ed6\u672a\u5217\u51fa\u7684\u961f\u4f0d\u6211\u4eec\u7ed9\u4e88\u6700\u4f4e\u7684\u6982\u7387\n        {\"\u8001\u9e70\", 1}, {\"\u51ef\u5c14\u7279\u4eba\", 1}, {\"\u7bee\u7f51\", 1}, {\"\u6e56\u4eba\", 1}, {\"\u7070\u718a\", 1},\n        {\"\u70ed\u706b\", 1}, {\"\u96c4\u9e7f\", 1}, {\"\u68ee\u6797\u72fc\", 1}, {\"\u5c3c\u514b\u65af\", 1}, {\"\u56fd\u738b\", 1},\n        {\"76\u4eba\", 1}, {\"\u592a\u9633\", 1}, {\"\u9a91\u58eb\", 1}, {\"\u6398\u91d1\", 1}, {\"\u52c7\u58eb\", 1}, {\"\u5feb\u8239\", 1},\n    }\n\n    for i := 0; len(teams) &gt; 0; i++ {\n        var picked *Team\n        picked, teams = weightedRandom(teams)\n        fmt.Printf(\"\u7b2c%d\u987a\u4f4d\u7403\u961f\u662f\uff1a%s\\n\", i+1, picked.name)\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u606d\u559c\u9a6c\u523a\u961f\u62bd\u4e2d\u4e86\u72b6\u5143\u7b7e\uff0c\u8fd9\u4e0b\u6587\u73ed\u4e9a\u9a6c\u8dd1\u4e0d\u8131\u4e86\u3002\u672a\u6765\u90fd\u662f\u4ed6\u4eec\u7684\u3002 \u5bf9\u8fd9\u4e2a\u9009\u79c0\u987a\u5e8f\u7a81\u7136\u6709\u70b9\u5174\u8da3\uff0c\u60f3\u60f3\u5e94\u8be5\u600e\u4e48\u53bb&hellip;<\/p>\n <a href=\"https:\/\/www.db2go.net\/?p=574\" title=\"\u6839\u636e\u5b98\u65b9\u7ed9\u51fa\u7684\u72b6\u5143\u7b7e\u6982\u7387\u6a21\u62dfNBA\u9009\u79c0\u987a\u4f4d\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">\u6839\u636e\u5b98\u65b9\u7ed9\u51fa\u7684\u72b6\u5143\u7b7e\u6982\u7387\u6a21\u62dfNBA\u9009\u79c0\u987a\u4f4d<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[12],"tags":[],"class_list":["entry","author-suredandan","post-574","post","type-post","status-publish","format-standard","category-golang"],"views":2211,"_links":{"self":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=574"}],"version-history":[{"count":3,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/574\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/574\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}