This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
My problem is : 05 Random r = new Random(); Line 05 is out of for loop(lines 07~09),and why r.nextInt(10) in for loop can point to the next pseudorandom number than get different pseudorandom numbers?? I mean that if I write code like this:
Why nextInt() get a point to a next and next and next pseudorandom number ??
I'm not sure what your question is. The for loop generates 10 distinct random integers for me. Can you post your output showing the problem? Tom Blough
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Joined: Feb 06, 2004
Output: Random Numbers :-1233322011 Random Numbers :-1849315457 Random Numbers :-1432212907 Random Numbers :-500641972 Random Numbers :450264059 Random Numbers :443463032 Random Numbers :2077564550 Random Numbers :938741894 Random Numbers :157277021 Random Numbers :1522514535 My question is why the output value of these 10 Random Numbers do't get the same one value?
Your confusion may come from what the purpose of "java.util.Random" is. When you do: Random r = new Random(); then "r" is a random number generator, not a random number itself. So once you instantiate the generator ("r") you can use it to create as many different random numbers as you need.
ChenSanHau, Welcome to JavaRanch! We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy. We'd like display names of the format first name(s) + SPACE + last name. Thanks Pardner! Hope to see you 'round the Ranch!