The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Execution Time

Posted by Nam Hu on November 07, 2001 at 1:38 PM

This is an interesting approach, but as the list of numbers generated gets closer to completion it will take more and more time for the generator to find a number that has not been generated yet. This, I think, would really bog down the program for a process that should be a bit less demanding on the CPU.

> You are right that it is possible to get repeats, just by using them on their own.

> I know it sounds inefficient, but you could maintain a vector of "numbers generated so far". Each time you generate a new number, add it to the vector. The inefficiency comes from having to check each vector element and see if the number generated matches any of them. If it does, you will need to generate a new number.

> I will have a think about how it could be done more elegantly.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us