

<rss version="2.0"
	xmlns:atom="http://www.w3.org/2005/Atom" 
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:admin="http://webns.net/mvcb/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
		
	<channel>
		<title>RSS Feeds :: DEVPPL - Forums > Java Forum : Topics : How to Generate Unique Random Numbers?</title>
	<!--<atom:link href="http://www.devppl.com/forum" rel="self" type="application/rss+xml" />-->
		<description>TOGETHER WE ARE THE BEST</description>
		<link>http://www.devppl.com/forum</link>
		<language>en-gb</language>
		<pubDate>Tue, 17 Aug 2004 14:07:13 +0100</pubDate>
		<lastBuildDate>Sat, 21 Nov 2009 11:17:38 +0000</lastBuildDate>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<generator>MSSTI v0.0.1 - (C) 2008 leviatan21 - http://www.mssti.com/</generator>
		<copyright>Copyright : (c) RSS Feeds :: DEVPPL - Tue, 17 Aug 2004 14:07:13 +0100</copyright>
		<dc:creator>webmaster@devppl.com (DEVPPL)</dc:creator>

		<image>
			<title>RSS Feeds :: DEVPPL - Forums > Java Forum : Topics : How to Generate Unique Random Numbers?</title>
			<url>http://www.devppl.com/forum/styles/DEVPPL/imageset/site_logo.gif</url>
			<link>http://www.devppl.com/forum</link>
		</image>
		<ttl>60</ttl>
		
		<item>
			<title>How to Generate Unique Random Numbers?</title>
			<link>http://www.devppl.com/forum/./viewtopic.php?p=46704#p46704</link>
				<description><![CDATA[ <div class="codetitle"><b>Code:</b></div><div class="codecontent"> <br
/><br /><br />import com.sun.crypto.provider.RSACipher;<br />import
java.util.Random;<br /><br />public class RandomRange &#123;<br /><br
/>&nbsp; &nbsp; static&nbsp; int START = 1;<br />&nbsp; &nbsp; static int
END;<br />&nbsp; &nbsp;static&nbsp; Random random = new
Random&#40;&#41;;<br />&nbsp; <br />&nbsp; &nbsp; private static void
showRandomInteger&#40;int aStart, int aEnd, Random aRandom&#41;&#123;<br
/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if &#40; aStart > aEnd &#41;
&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw
new IllegalArgumentException&#40;"Start cannot exceed End."&#41;;<br
/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; //get the range, casting to long to avoid
overflow problems<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long range
= &#40;long&#41;aEnd - &#40;long&#41;aStart + 1;<br />&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; // compute a fraction of the range, 0 <= frac <
range<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long fraction =
&#40;long&#41;&#40;range * aRandom.nextDouble&#40;&#41;&#41;;<br />&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int randomNumber =&nbsp;
&#40;int&#41;&#40;fraction + aStart&#41;;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; //&nbsp; System.out.println&#40;"Hi this is from senthil ==
>"+ j &#41;;<br /> </div>...<p>Statistics : Posted by <a href="http://www.devppl.com/forum/memberlist.php?mode=viewprofile&amp;u=18637">randy_ortan</a> &bull; on Mon Sep 22, 2008 7:49 am &bull; Replies 0 &bull; Views 492</p><hr />]]></description>
					<content:encoded><![CDATA[ <div class="codetitle"><b>Code:</b></div><div class="codecontent"> <br
/><br /><br />import com.sun.crypto.provider.RSACipher;<br />import
java.util.Random;<br /><br />public class RandomRange &#123;<br /><br
/>&nbsp; &nbsp; static&nbsp; int START = 1;<br />&nbsp; &nbsp; static int
END;<br />&nbsp; &nbsp;static&nbsp; Random random = new
Random&#40;&#41;;<br />&nbsp; <br />&nbsp; &nbsp; private static void
showRandomInteger&#40;int aStart, int aEnd, Random aRandom&#41;&#123;<br
/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if &#40; aStart > aEnd &#41;
&#123;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw
new IllegalArgumentException&#40;"Start cannot exceed End."&#41;;<br
/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#125;<br />&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; //get the range, casting to long to avoid
overflow problems<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long range
= &#40;long&#41;aEnd - &#40;long&#41;aStart + 1;<br />&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; // compute a fraction of the range, 0 <= frac <
range<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long fraction =
&#40;long&#41;&#40;range * aRandom.nextDouble&#40;&#41;&#41;;<br />&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int randomNumber =&nbsp;
&#40;int&#41;&#40;fraction + aStart&#41;;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; //&nbsp; System.out.println&#40;"Hi this is from senthil ==
>"+ j &#41;;<br /> </div>...]]></content:encoded>
					<category domain="http://www.devppl.com/forum/viewforum.php?f=47"><![CDATA[Java Forum]]></category>
			<dc:creator><![CDATA[18637]]></dc:creator>
			<dc:date>2008-09-22T07:49:05+01:00</dc:date>
			<guid isPermaLink="false">http://www.devppl.com/forum/./viewtopic.php?p=46704#p46704</guid>
		</item>
	
	</channel>
</rss>