{"id":533,"date":"2022-09-26T17:10:14","date_gmt":"2022-09-26T09:10:14","guid":{"rendered":"https:\/\/qaqaq.top\/?p=533"},"modified":"2022-11-27T12:40:00","modified_gmt":"2022-11-27T04:40:00","slug":"java%e9%9a%8f%e6%9c%ba%e6%95%b0%e7%9c%9f%e7%9a%84%e9%9a%8f%e6%9c%ba%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=533","title":{"rendered":"JAVA\u968f\u673a\u6570\u771f\u7684\u968f\u673a\u5417\uff1f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u968f\u673a\u6570<\/h2>\n\n\n\n<p>java\u7684\u968f\u673a\u6570\u771f\u7684\u975e\u5e38\u6613\u4e8e\u4f7f\u7528\u3002\u5b83\u53ef\u4ee5\u8ba9\u4f60\u6a21\u62df\u51c6\u786e\u7684\u7edf\u8ba1\u6837\u672c\u3001\u5b9e\u73b0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u4f60\u53ef\u4ee5\u4e0d\u5047\u601d\u7d22\u5730\u4f7f\u7528\u3002\u5728Java\u4e2d\uff0c\u8bbf\u95ee\u968f\u673a\u6570\u7684\u5e38\u7528\u65b9\u6cd5\u662f\u901a\u8fc7\u4e00\u4e2a\u540d\u4e3a&nbsp;<a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/Random.html\">java.util.Random<\/a>\u7684\u7c7b\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u79cd\u5b50\u6570\u6216\u5f53\u524d\u65f6\u95f4\u6765\u5b9e\u4f8b\u5316\u5b83\uff0c\u7136\u540e\u60a8\u5c31\u6709\u4e86\u4e00\u7cfb\u5217\u7684\u503c\uff0c\u4f60\u53ef\u4ee5\u5f88\u8f7b\u6613\u7684\u8bbf\u95ee\u8fd9\u4e9b\u503c\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Random random = new Random();\n\/\/ Prints out either 0 or 1\nSystem.out.println(random.nextInt(2));<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528\u6237\u53c2\u4e0e\u65f6\u95f4<\/h2>\n\n\n\n<p>\u5982\u679c\u60a8\u7684\u671f\u671b\u6ca1\u6709\u56e0\u4ee5\u4e0b\u95ee\u9898\u800c\u4ea7\u751f\u504f\u5dee\uff1a\u60a8\u53ef\u4ee5\u6253\u5370\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void main(String&#91;] args) {\n       int start = 0;\n       int end = 1000;\n       int countOnes = 0;\n       for (int i = start; i &lt; end; i++) {\n             countOnes += new Random(i).nextInt(2);\n            }\n       System.out.println(countOnes);\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u6211\u4eec\u4f1a\u5f97\u5230\u4e00\u4e0b\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> 1000<\/code><\/pre>\n\n\n\n<p>\u8fd9\u592a\u4ee4\u4eba\u60ca\u8bb6\u4e86\u2014\u2014\u5982\u679c\u4f60\u95ee\u6211\u9884\u671f\u7684\u6570\u5b57\u662f\u591a\u5c11\uff0c\u6211\u4f1a\u544a\u8bc9\u4f60\uff0c\u6211\u4e0d\u80fd\u7ed9\u4f60\u4e00\u4e2a\u786e\u5207\u7684\u6570\u5b57\uff0c\u4f46\u6211\u9884\u8ba1\u5927\u7ea6\u662f500\u3002\u8fd9\u662f\u57fa\u4e8e\u8fd9\u6837\u4e00\u4e2a\u5047\u8bbe\uff0c\u4ee5\u4e3a\u968f\u673a\u6570\u7684\u6982\u7387\u5429\u5490\u7b26\u5408\u5747\u5300\u5206\u5e03\uff0c\u56e0\u6b64\u7ed3\u679c\u4e3a1\u548c0\u7684\u6982\u7387\u90fd\u662f50%\u3002\u5b83\u4e0d\u4f1a\u7cbe\u786e\u5730\u8ba1\u7b97\u51fa500\uff0c\u4f46\u5982\u679c\u6837\u672c\u91cf\u4e3a1000\uff0c\u90a3\u4e48\u603b\u6570\u5c06\u63a5\u8fd1500\u3002\u5982\u679c\u6211\u4eec\u5c06\u7ec8\u70b9\u503c\u66f4\u6539\u4e3a4000\uff0c\u5219\u4f1a\u5f97\u5230\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>4000\n<\/code><\/pre>\n\n\n\n<p>\u518d\u6b21\u8c03\u7528nextInt\uff082\uff09\u5e94\u8be5\u8fd4\u56de\u4e00\u4e2a\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\u7684\u968f\u673a\u6570\uff0c\u4f46\u5b83\u53ea\u8fd4\u56de1\u3002\u6211\u4eec\u8bbe\u7f6e\uff0c\u8d77\u70b9\u4e3a4000\uff0c\u7ec8\u70b9\u4e3a5000\uff0c\u7ed3\u679c\u53c8\u4f1a\u600e\u4e48\u6837\u5462\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>96<\/code><\/pre>\n\n\n\n<p>\u597d\u7684\uff0c\u6211\u73b0\u5728\u6709\u66f4\u591a\u7684\u96f6\uff0c\u4f46\u6bd4\u6211\u9884\u671f\u7684\u8981\u5c11\u5f88\u591a\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837\uff1f<\/h1>\n\n\n\n<p>\u4eba\u4eec\u901a\u5e38\u5c06\u57fa\u4e8e\u8ba1\u7b97\u673a\u7684\u968f\u673a\u6570\u751f\u6210\u5668\u79f0\u4e3a\u4f2a\u968f\u673a\u6570\u751f\u6210\u5668\uff0c\u4f46\u5b83\u5f88\u5c11\u63cf\u8ff0\u4f2a\u968f\u673a\u7684\u5b9e\u9645\u542b\u4e49\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u771f\u6b63\u7684\u610f\u601d\u662f\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u7b97\u6cd5\uff0c\u8fd9\u4e2a\u7b97\u6cd5\u4ea7\u751f\u4e00\u4e2a\u786e\u5b9a\u6027\u7684\u6570\u5b57\u5e8f\u5217\uff0c\u8fd9\u4e2a\u5e8f\u5217\u662f\u7531\u4e00\u4e2a\u79cd\u5b50\u6570\u521d\u59cb\u5316\u7684\u3002\u8fd9\u4e2a\u5e8f\u5217\u770b\u8d77\u6765\u5f88\u968f\u673a\uff0c\u4f46\u5b83\u53ea\u662f\u8868\u9762\u73b0\u8c61\u3002\u4e0a\u9762\u7684\u5c0f\u7a0b\u5e8f\u6240\u505a\u7684\u53ea\u662f\u4ece\u5e8f\u5217\u4e2d\u62bd\u53d6\u7b2c\u4e00\u4e2a\u968f\u673a\u6570\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u7b97\u6cd5\uff0c\u4f46\u5b83\u786e\u5b9e\u5f15\u53d1\u4e86\u4e00\u4e9b\u6709\u8da3\u7684\u95ee\u9898\uff0cjava.util.Random\u4f7f\u7528\u7ebf\u6027\u540c\u4f59\u751f\u6210\u5668\u751f\u6210\u5176\u6570\u5b57\uff0c\u5176\u4f18\u70b9\u662f\u7b80\u5355\u5feb\u901f\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u6837\u505a\u7684\u4ee3\u4ef7\u662f\u5b83\u4e0d\u662f\u5f88\u968f\u673a\u7684\u2014\u2014\u5373\u4f7f\u7a0b\u5e8f\u5458\u6b63\u786e\u5730\u4f7f\u7528\u5b83\u3002\u5b83\u4e5f\u6839\u672c\u4e0d\u9002\u5408\u8499\u7279\u5361\u7f57\u6a21\u62df\u6216\u6676\u4f53\u7b97\u6cd5\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e5f\u4e0d\u662fJava\u7279\u6709\u7684\u95ee\u9898python\u7684\u65e9\u671f\u7248\u672c\u4f7f\u7528\u4e86Wichmann&amp;Hill 1982\u5e74\u7684\u7b97\u6cd5\u3002\u8fd9\u4f1a\u53d7\u5230\u77ed\u671f\u5f71\u54cd\uff0c\u8fd9\u610f\u5473\u7740\u6570\u5b57\u5728\u4e00\u6bb5\u65f6\u95f4\u540e\u5f00\u59cb\u91cd\u590d\u3002\u6700\u8fd1\u7684\u7248\u672c\u4f7f\u7528Mersenne Twister\u4f5c\u4e3a\u5176\u7b97\u6cd5\uff0c\u8be5\u7b97\u6cd5\u5177\u6709\u66f4\u597d\u7684\u7279\u6027\uff0c\u4f46\u4ecd\u7136\u4e0d\u9002\u5408\u7528\u4e8e\u52a0\u5bc6\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u603b\u7ed3<\/h1>\n\n\n\n<p>\u5728\u6240\u6709\u8fd9\u4e9b\u60c5\u51b5\u4e0b\u9700\u8981\u8bb0\u4f4f\u7684\u662f\uff0c\u4f2a\u968f\u673a\u6570\u4e0d\u662f\u968f\u673a\u6570\uff0c\u5982\u679c\u60a8\u5173\u5fc3\u7edf\u8ba1\u968f\u673a\u6027\uff0c\u90a3\u4e48\u60a8\u9700\u8981\u5728\u7b97\u6cd5\u9009\u62e9\u548c\u5b9e\u73b0\u4f7f\u7528\u65b9\u9762\u90fd\u52a0\u4ee5\u6ce8\u610f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u673a\u6570 java\u7684\u968f\u673a\u6570\u771f\u7684\u975e\u5e38\u6613\u4e8e\u4f7f\u7528\u3002\u5b83\u53ef\u4ee5\u8ba9\u4f60\u6a21\u62df\u51c6\u786e\u7684\u7edf\u8ba1\u6837\u672c\u3001\u5b9e\u73b0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u4f60\u53ef\u4ee5\u4e0d\u5047\u601d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[46],"class_list":["post-533","post","type-post","status-publish","format-standard","hentry","category-java-","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/533"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=533"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/533\/revisions"}],"predecessor-version":[{"id":534,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/533\/revisions\/534"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}