{"id":1601,"date":"2024-11-10T15:29:33","date_gmt":"2024-11-10T07:29:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1601\/"},"modified":"2024-11-10T15:29:33","modified_gmt":"2024-11-10T07:29:33","slug":"javascript-%e4%b8%ad%e9%9a%8f%e6%9c%ba%e6%95%b0%e7%94%9f%e6%88%90%ef%bc%9a%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e4%b8%8d%e5%90%8c%e8%8c%83%e5%9b%b4%e5%92%8c%e7%b1%bb%e5%9e%8b%e7%9a%84%e9%9a%8f%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1601\/","title":{"rendered":"JavaScript \u4e2d\u968f\u673a\u6570\u751f\u6210\uff1a\u5982\u4f55\u751f\u6210\u4e0d\u540c\u8303\u56f4\u548c\u7c7b\u578b\u7684\u968f\u673a\u6570\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173051054763306.jpg\" class=\"aligncenter\" title=\"JavaScript \u4e2d\u968f\u673a\u6570\u751f\u6210\uff1a\u5982\u4f55\u751f\u6210\u4e0d\u540c\u8303\u56f4\u548c\u7c7b\u578b\u7684\u968f\u673a\u6570\uff1f\u63d2\u56fe\" alt=\"JavaScript \u4e2d\u968f\u673a\u6570\u751f\u6210\uff1a\u5982\u4f55\u751f\u6210\u4e0d\u540c\u8303\u56f4\u548c\u7c7b\u578b\u7684\u968f\u673a\u6570\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>JS \u968f\u673a\u6570\u751f\u6210\uff1a\u591a\u79cd\u5199\u6cd5<\/strong><\/p>\n<p>\u5728 JavaScript \u4e2d\u751f\u6210\u968f\u673a\u6570\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f Math.random() \u51fd\u6570\u3002<\/p>\n<p>Math.random() \u4f1a\u8fd4\u56de 0 \u5230 1 \u4e4b\u95f4\u7684\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002\u8981\u751f\u6210\u4e00\u4e2a\u6574\u6570\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u5c06\u5176\u4e0e\u5176\u4ed6 Math \u51fd\u6570\u7ed3\u5408\u4f7f\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>Math.round(Math.random())\uff1a\u751f\u6210\u968f\u673a 0 \u6216 1\u3002<\/li>\n<li>Math.floor(Math.random() * 10)\uff1a\u751f\u6210 0 \u5230 9 \u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u3002<\/li>\n<li>Math.floor(Math.random() * 10) % 3\uff1a\u751f\u6210 0 \u5230 2 \u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u3002<\/li>\n<li>Math.round(Math.random() * (Max &#8211; Min) + Min)\uff1a\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6574\u6570\uff0c\u4ecb\u4e8e Max \u548c Min\uff08\u5305\u542b\uff09\u4e4b\u95f4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript \u4e2d\u968f\u673a\u6570\u751f\u6210\uff1a\u5982\u4f55\u751f\u6210\u4e0d\u540c\u8303\u56f4\u548c\u7c7b\u578b\u7684\u968f\u673a\u6570\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JS \u968f\u673a\u6570\u751f\u6210\uff1a\u591a\u79cd\u5199\u6cd5 \u5728 JavaScript \u4e2d\u751f\u6210\u968f\u673a\u6570\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f Math.random() \u51fd\u6570\u3002 Math.random() \u4f1a\u8fd4\u56de 0 \u5230 1 \u4e4b\u95f4\u7684\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002\u8981\u751f\u6210\u4e00\u4e2a\u6574\u6570\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u5c06\u5176\u4e0e\u5176\u4ed6 Math \u51fd\u6570\u7ed3\u5408\u4f7f\u7528\uff0c\u4f8b\u5982\uff1a Math.round(Math.random())\uff1a\u751f\u6210\u968f\u673a 0 \u6216 1\u3002 Math.floor(Math.random() * 10)\uff1a\u751f\u6210 0 \u5230 9 \u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u3002 Math.floor(Math.random() * 10) % 3\uff1a\u751f\u6210 0 \u5230 2 \u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u3002 Math.round(Math.random() * (Max &#8211; Min) + Min)\uff1a\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6574\u6570\uff0c\u4ecb\u4e8e Max \u548c Min\uff08\u5305\u542b\uff09\u4e4b\u95f4\u3002 \u4ee5\u4e0a\u5c31\u662fJavaScript \u4e2d\u968f\u673a\u6570\u751f\u6210\uff1a\u5982\u4f55\u751f\u6210\u4e0d\u540c\u8303\u56f4\u548c\u7c7b\u578b\u7684\u968f\u673a\u6570\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1601","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1601"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1601\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}