commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Schaible <Joerg.Schai...@Elsag-Solutions.com>
Subject RE: [POLL] System.currentTimeMillis()
Date Fri, 16 Dec 2005 09:34:45 GMT
Boris Unckel wrote on Thursday, December 15, 2005 6:55 PM:

> Hi Joerg,
> 
> this is an absolutely "normal" behaviour. It does not depend
> on the operating system, but more on system speed.
> Your CPU has enough power to calculate n-thousand additions
> in one milli second.
> It is not predictable, since it depends on the machine in use.

Well, it was not the problem, that the system millis do not increase (or stay the same) for
successive calls, the problem is that they *decrease*.

> I have found this in an other context:
> Random  r1 = new Random(); //depends on System.currentMillis()
> 
> If you have the need to randomize more than one number (and cannot
> rely on the same random object) you need one random for the seed,
> and one random for the number generating:
> 
> private static final Random RANDOM_FOR_SEED = new Random(); //....
> public int generateRandomInt(){
>  Random localRandom = new Random(RANDOM_FOR_SEED.nextLong());
>  return localRandom.nextInt(100);
> }

Your case would not be affected by a decreasing value ... ;-)

- Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message