{"id":1653,"date":"2024-11-10T15:28:29","date_gmt":"2024-11-10T07:28:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1653\/"},"modified":"2024-11-10T15:28:29","modified_gmt":"2024-11-10T07:28:29","slug":"js-%e9%81%8d%e5%8e%86%e5%be%aa%e7%8e%af%e4%b8%ad-math-random-%e7%94%9f%e6%88%90%e7%9a%84%e9%9a%8f%e6%9c%ba%e6%95%b0%e9%87%8d%e5%a4%8d%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1653\/","title":{"rendered":"JS \u904d\u5386\u5faa\u73af\u4e2d Math.random() \u751f\u6210\u7684\u968f\u673a\u6570\u91cd\u590d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173052695953172.jpg\" class=\"aligncenter\" title=\"JS \u904d\u5386\u5faa\u73af\u4e2d Math.random() \u751f\u6210\u7684\u968f\u673a\u6570\u91cd\u590d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"JS \u904d\u5386\u5faa\u73af\u4e2d Math.random() \u751f\u6210\u7684\u968f\u673a\u6570\u91cd\u590d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js \u5728\u904d\u5386\u4e2d\u4f7f\u7528 math.random() \u51fd\u6570\u751f\u6210\u7684\u6570\u636e\u76f8\u540c\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 math.random() \u51fd\u6570\u751f\u6210\u968f\u673a\u6570\u65f6\uff0c\u5982\u679c\u5728\u904d\u5386\u8fc7\u7a0b\u4e2d\u8fde\u7eed\u4f7f\u7528\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u751f\u6210\u7684\u6570\u636e\u76f8\u540c\u7684\u73b0\u8c61\u3002\u8fd9\u662f\u56e0\u4e3a math.random() \u51fd\u6570\u672c\u8eab\u4f1a\u8fd4\u56de\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5e76\u4e14\u5728\u8fde\u7eed\u8c03\u7528\u65f6\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u76f8\u540c\u7684\u5e8f\u5217\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u786e\u4fdd\u5728\u6bcf\u6b21\u8c03\u7528 math.random() \u51fd\u6570\u4e4b\u524d\u8bbe\u7f6e\u79cd\u5b50\u503c<\/strong><\/p>\n<p>\u8fd9\u6837\u505a\u53ef\u4ee5\u5c06\u51fd\u6570\u91cd\u65b0\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u4e0d\u540c\u7684\u968f\u673a\u72b6\u6001\uff0c\u5e76\u786e\u4fdd\u751f\u6210\u4e0d\u540c\u7684\u968f\u673a\u6570\u3002<\/p>\n<p><strong>\u4f7f\u7528\u4e0d\u540c\u7684\u968f\u673a\u6570\u751f\u6210\u7b97\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86 math.random() \u51fd\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u968f\u673a\u6570\u751f\u6210\u7b97\u6cd5\uff0c\u4f8b\u5982 crypto.getrandomvalues() \u6216 faker.js \u4e2d\u7684\u5e93\u3002\u8fd9\u4e9b\u7b97\u6cd5\u53ef\u80fd\u4f1a\u751f\u6210\u66f4\u4e0d\u53ef\u9884\u6d4b\u7684\u968f\u673a\u6570\u5e8f\u5217\u3002<\/p>\n<p><strong>\u6392\u9664\u91cd\u590d<\/strong><\/p>\n<p>\u5728\u751f\u6210\u968f\u673a\u6570\u540e\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5e76\u68c0\u67e5\u6570\u7ec4\u4e2d\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u8be5\u6570\u5b57\u3002\u5982\u679c\u5b58\u5728\uff0c\u5219\u518d\u6b21\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6570\u3002<\/p>\n<p>\u5728\u4f60\u7684\u5177\u4f53\u793a\u4f8b\u4e2d\uff0c\u95ee\u9898\u51fa\u5728\u7b2c\u4e8c\u4e2a push \u8bed\u53e5\u4e2d\u4e5f\u4f7f\u7528\u4e86 &#8220;expect&#8221;\u3002\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f\u5c06\u7b2c\u4e8c\u4e2a\u968f\u673a\u6570\u53d8\u91cf\u547d\u540d\u4e3a &#8220;practical&#8221;\uff1a<\/p>\n<pre>const el = {\n  expect: Math.random(),\n  practical: Math.random()\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJS \u904d\u5386\u5faa\u73af\u4e2d Math.random() \u751f\u6210\u7684\u968f\u673a\u6570\u91cd\u590d\uff0c\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>js \u5728\u904d\u5386\u4e2d\u4f7f\u7528 math.random() \u51fd\u6570\u751f\u6210\u7684\u6570\u636e\u76f8\u540c\uff0c\u5982\u4f55\u89e3\u51b3\uff1f \u5728\u4f7f\u7528 math.random() \u51fd\u6570\u751f\u6210\u968f\u673a\u6570\u65f6\uff0c\u5982\u679c\u5728\u904d\u5386\u8fc7\u7a0b\u4e2d\u8fde\u7eed\u4f7f\u7528\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u751f\u6210\u7684\u6570\u636e\u76f8\u540c\u7684\u73b0\u8c61\u3002\u8fd9\u662f\u56e0\u4e3a math.random() \u51fd\u6570\u672c\u8eab\u4f1a\u8fd4\u56de\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5e76\u4e14\u5728\u8fde\u7eed\u8c03\u7528\u65f6\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u76f8\u540c\u7684\u5e8f\u5217\u3002 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u786e\u4fdd\u5728\u6bcf\u6b21\u8c03\u7528 math.random() \u51fd\u6570\u4e4b\u524d\u8bbe\u7f6e\u79cd\u5b50\u503c \u8fd9\u6837\u505a\u53ef\u4ee5\u5c06\u51fd\u6570\u91cd\u65b0\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u4e0d\u540c\u7684\u968f\u673a\u72b6\u6001\uff0c\u5e76\u786e\u4fdd\u751f\u6210\u4e0d\u540c\u7684\u968f\u673a\u6570\u3002 \u4f7f\u7528\u4e0d\u540c\u7684\u968f\u673a\u6570\u751f\u6210\u7b97\u6cd5 \u9664\u4e86 math.random() \u51fd\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u968f\u673a\u6570\u751f\u6210\u7b97\u6cd5\uff0c\u4f8b\u5982 crypto.getrandomvalues() \u6216 faker.js \u4e2d\u7684\u5e93\u3002\u8fd9\u4e9b\u7b97\u6cd5\u53ef\u80fd\u4f1a\u751f\u6210\u66f4\u4e0d\u53ef\u9884\u6d4b\u7684\u968f\u673a\u6570\u5e8f\u5217\u3002 \u6392\u9664\u91cd\u590d \u5728\u751f\u6210\u968f\u673a\u6570\u540e\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5e76\u68c0\u67e5\u6570\u7ec4\u4e2d\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u8be5\u6570\u5b57\u3002\u5982\u679c\u5b58\u5728\uff0c\u5219\u518d\u6b21\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6570\u3002 \u5728\u4f60\u7684\u5177\u4f53\u793a\u4f8b\u4e2d\uff0c\u95ee\u9898\u51fa\u5728\u7b2c\u4e8c\u4e2a push \u8bed\u53e5\u4e2d\u4e5f\u4f7f\u7528\u4e86 &#8220;expect&#8221;\u3002\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f\u5c06\u7b2c\u4e8c\u4e2a\u968f\u673a\u6570\u53d8\u91cf\u547d\u540d\u4e3a &#8220;practical&#8221;\uff1a const el = { expect: Math.random(), practical: Math.random() }; \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fJS \u904d\u5386\u5faa\u73af\u4e2d Math.random() \u751f\u6210\u7684\u968f\u673a\u6570\u91cd\u590d\uff0c\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1653","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1653","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=1653"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1653\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}