{"id":253,"date":"2007-09-26T00:00:00","date_gmt":"2007-09-26T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=253"},"modified":"2007-09-26T00:00:00","modified_gmt":"2007-09-26T00:00:00","slug":"Generate not repeat random numbers","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=253","title":{"rendered":"Generate not repeat random numbers"},"content":{"rendered":"<p><DIV><br \/>\n<DIV>for(int i=;i&lt;100;i++){<\/DIV><br \/>\n<DIV>ArrayList&lt;Integer&gt; tmp_l = new ArrayList&lt;Integer&gt;();<\/DIV><br \/>\n<DIV>int pos =&nbsp;100;<BR>int serial = (int)Math.round(Math.random()*(pos-1));<BR>int loopcontrol = 0;<BR><\/DIV><br \/>\n<DIV>while(tmp_l.contains(serial)){<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(loopcontrol&gt;100) break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;serial = (int)Math.round(Math.random()*(pos-1));<BR>&nbsp;&nbsp;&nbsp;&nbsp;loopcontrol ++;<BR>}<BR>&nbsp;&nbsp;&nbsp;<BR>tmp_l.add(serial);<\/DIV><br \/>\n<DIV>System.out.println(&#8220;The random number for &#8220;+i+&#8221; is:&#8221;+serial);<\/DIV><br \/>\n<DIV>}<\/DIV><br \/>\n<DIV>\u53ea\u7d66\u51fa\u4ee3\u78bc\u7247\u6bb5,<\/DIV><br \/>\n<DIV>\u5148\u6709\u6a5f\u51fa\u4e00\u500b\u6578,\u4fdd\u5b58\u5728ArrayList,\u518d\u6709\u6a5f\u7b2c\u4e8c\u500b\u6578,\u770b\u770b\u662f\u5426\u5b58\u5728\u65bcArrayList\u4e2d,\u5982\u679c\u5b58\u5728,\u518d\u91cd\u65b0\u6709\u6a5f\u7b2c\u4e8c\u500b\u6578.\u5982\u6b64\u985e\u63a8..\u76f4\u5230\u5b8c\u6210100\u500b\u6709\u6a5f\u6578\u70ba\u6b64!<\/DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>for(int i=;i&lt;100;i++){ ArrayList&lt;Integer&gt; tmp_l = new ArrayList&lt;Integer&gt;(); int pos =&nbsp;100;int serial = (int)Math.round(Math.random()*(pos-1));int loopcontrol = 0; while(tmp_l.contains(serial)){&nbsp;&nbsp;&nbsp;&nbsp;if(loopcontrol&gt;100) break;&nbsp;&nbsp;&nbsp;&nbsp;serial = (int)Math.round(Math.random()*(pos-1));&nbsp;&nbsp;&nbsp;&nbsp;loopcontrol ++;}&nbsp;&nbsp;&nbsp;tmp_l.add(serial); System.out.println(&#8220;The random number for &#8220;+i+&#8221; is:&#8221;+serial); } \u53ea\u7d66\u51fa\u4ee3\u78bc\u7247\u6bb5, \u5148\u6709\u6a5f\u51fa\u4e00\u500b\u6578,\u4fdd\u5b58\u5728ArrayList,\u518d\u6709\u6a5f\u7b2c\u4e8c\u500b\u6578,\u770b\u770b\u662f\u5426\u5b58\u5728\u65bcArrayList\u4e2d,\u5982\u679c\u5b58\u5728,\u518d\u91cd\u65b0\u6709\u6a5f\u7b2c\u4e8c\u500b\u6578.\u5982\u6b64\u985e\u63a8..\u76f4\u5230\u5b8c\u6210100\u500b\u6709\u6a5f\u6578\u70ba\u6b64!<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=253"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}