{"id":1723,"date":"2024-11-10T11:55:59","date_gmt":"2024-11-10T03:55:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1723\/"},"modified":"2024-11-10T11:55:59","modified_gmt":"2024-11-10T03:55:59","slug":"javascript-%e9%81%8d%e5%8e%86%e4%b8%ad-math-random-%e8%bf%94%e5%9b%9e%e5%80%bc%e5%a7%8b%e7%bb%88%e7%9b%b8%e5%90%8c%ef%bc%9f%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1723\/","title":{"rendered":"JavaScript \u904d\u5386\u4e2d Math.random() \u8fd4\u56de\u503c\u59cb\u7ec8\u76f8\u540c\uff1f\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173054396599647.jpg\" class=\"aligncenter\" title=\"JavaScript \u904d\u5386\u4e2d Math.random() \u8fd4\u56de\u503c\u59cb\u7ec8\u76f8\u540c\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"JavaScript \u904d\u5386\u4e2d Math.random() \u8fd4\u56de\u503c\u59cb\u7ec8\u76f8\u540c\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>javascript \u4e2d math.random() \u8fd4\u56de\u7684\u503c\u5728\u904d\u5386\u4e2d\u59cb\u7ec8\u76f8\u540c<\/strong><\/p>\n<p>\u5728\u8fdb\u884c javascript \u904d\u5386\u65f6\uff0c\u4f7f\u7528 math.random() \u51fd\u6570\u751f\u6210\u968f\u673a\u6570\u53ef\u80fd\u5bfc\u81f4\u6240\u6709\u7ed3\u679c\u76f8\u540c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u786e\u4fdd\u6bcf\u6b21\u8c03\u7528 math.random() \u51fd\u6570\u65f6\uff0c\u751f\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u968f\u673a\u503c\u3002<\/p>\n<p>\u5e38\u2ec5\u8bef\u89e3\uff1a<\/p>\n<pre>let arr = [0, 1, 2];\narr.foreach((el) =&gt; { const practical = math.random(); el.expect = practical; });<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u867d\u7136 math.random() \u4f1a\u5728\u7b2c\u4e00\u6b21\u8c03\u7528\u65f6\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6570\uff0c\u4f46\u968f\u540e\u7684\u8c03\u7528\u4f1a\u8fd4\u56de\u76f8\u540c\u7684\u503c\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u5faa\u73af\u4e2d\u4f7f\u7528\u540c\u4e00\u4e2a practical \u53d8\u91cf\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u4e3a\u6bcf\u4e2a\u5143\u7d20\u751f\u6210\u4e0d\u540c\u7684\u968f\u673a\u503c\uff0c\u9700\u8981\u5c06 math.random() \u8c03\u7528\u653e\u5230\u5faa\u73af\u5185\uff1a<\/p>\n<pre>let arr = [0, 1, 2];\narr.forEach((el) =&gt; { el.expect = Math.random(); });<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d\u90fd\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6570\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript \u904d\u5386\u4e2d Math.random() \u8fd4\u56de\u503c\u59cb\u7ec8\u76f8\u540c\uff1f\u5982\u4f55\u89e3\u51b3\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>javascript \u4e2d math.random() \u8fd4\u56de\u7684\u503c\u5728\u904d\u5386\u4e2d\u59cb\u7ec8\u76f8\u540c \u5728\u8fdb\u884c javascript \u904d\u5386\u65f6\uff0c\u4f7f\u7528 math.random() \u51fd\u6570\u751f\u6210\u968f\u673a\u6570\u53ef\u80fd\u5bfc\u81f4\u6240\u6709\u7ed3\u679c\u76f8\u540c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u786e\u4fdd\u6bcf\u6b21\u8c03\u7528 math.random() \u51fd\u6570\u65f6\uff0c\u751f\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u968f\u673a\u503c\u3002 \u5e38\u2ec5\u8bef\u89e3\uff1a let arr = [0, 1, 2]; arr.foreach((el) =&gt; { const practical = math.random(); el.expect = practical; }); \u767b\u5f55\u540e\u590d\u5236 \u867d\u7136 math.random() \u4f1a\u5728\u7b2c\u4e00\u6b21\u8c03\u7528\u65f6\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6570\uff0c\u4f46\u968f\u540e\u7684\u8c03\u7528\u4f1a\u8fd4\u56de\u76f8\u540c\u7684\u503c\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u5faa\u73af\u4e2d\u4f7f\u7528\u540c\u4e00\u4e2a practical \u53d8\u91cf\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u4e3a\u6bcf\u4e2a\u5143\u7d20\u751f\u6210\u4e0d\u540c\u7684\u968f\u673a\u503c\uff0c\u9700\u8981\u5c06 math.random() \u8c03\u7528\u653e\u5230\u5faa\u73af\u5185\uff1a let arr = [0, 1, 2]; arr.forEach((el) =&gt; { el.expect = Math.random(); }); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u6837\uff0c\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d\u90fd\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6570\u3002 [&hellip;]<\/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-1723","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1723","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=1723"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1723\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}