If you call this line of code on consecutive lines, then yes, two random instances that you create can be created with the same seed from the clock (counting the number of seconds milliseconds is the default value for Random objects). Almost universally, if an application requires multiple random numbers, you should create one instance of Random and reuse it as often as you need.
Edit: It is interesting to note that javadoc for Random has changed from 1.4.2, which explains that the clock is used as the default seed. Apparently, this is no longer a guarantee.
Edit # 2: By the way, even with a properly selected instance of Random that you are reusing, you will still get the same random number as the previous call, about 1/5 times when you call nextInt(5) .
public static void main(String[] args) { Random rand = new Random(); int count = 0; int trials = 10000; int current; int previous = rand.nextInt(5); for(int i=0; i < trials; ++i) { current = rand.nextInt(5); if( current == previous ) { count++; } } System.out.println("Random int was the same as previous " + count + " times out of " + trials + " tries."); }
source share