| Author |
Generation of Random Number
|
Srinivas Kalvala
Ranch Hand
Joined: Oct 20, 2005
Posts: 257
|
|
Hello, Can any one help me in generating random number sequence for real time application. with following constraint, the routine should not access the current time stamp or db time stamp. I have tried with util.Random and math.random() they are not generated unique random numbers, after a period of time , say after every 100 or 150 numbers , they are generating again same set of numbers. Help required.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
unique random numbers
There is nothing in either of those classes that guarentees uniqueness. If this is a single JVM application, you might look at the UID class
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
The difficulty is in the fact that you want unique numbers. You could do this by first making a list of all possible numbers, and then call Collections.shuffle(...) on the list to put them in random order. Then you just iterate the list to get random numbers. This solution might not be practical if the range of all possible numbers is large, or when you need a lot of random numbers.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Generation of Random Number
|
|
|