Same input different output..time calculation
<p>I have a knotty problem to solve.
I use System.currentTimeMillis() before a method call and immediately after that since
I have to measure the time elapsed beetween those two statements.</p>

<pre><code>waitingTime = System.currentTimeMillis(); //starts calculating time
bridge.getIn(direction); // tries to enter the bridge   
waitingTime = System.currentTimeMillis() - waitingTime ;// time elapsed
</code></pre>

<p>My concern is that I get different result everytime I run the program.</p>

<p>I get this (which is perfect):</p>

<pre><code>Generated cars going north: 0 
Generated cars going south: 2

Waiting time for every single car:
==============================================================
A0/South:109ms
A1/South:0ms
==============================================================
Mean waiting time southbound cars : 54ms
</code></pre>

<p>Then a few seconds later I run the program again and I get (which is wrong):</p>

<pre><code>Generated cars going north: 0 
Generated cars going south: 2

Waiting time for every single car:
==============================================================
A0/South:0ms
A1/South:94ms
==============================================================
Mean waiting time southbound cars : 47ms
</code></pre>

<p>I say this output is wrong since the waiting time for every car should never be less than 100ms.</p>

<p>What does actually affect time calculation based on the currentTimeMillis function?</p>

<p>why do I get different results?</p>

<p>One might wonder: is the input the same every time? I would say yes.. the input parameters </p>

<p>are always the same (both examples) but the program uses the Random class to generate a </p>

<p>given number of threads.</p>

<p>Is that the culprit?</p>

<p>A few details abou the program:</p>

<p>A bunch of cars going from north to south (viceversa) travel along a two lane road. 
After a while they reach a bridge. The bridge is one way only and it has limited capacity. 
A car takes 100ms to go through the bridge. No traffic collision are allowed.</p>

<p>Thanks a lot.</p>
