Hi there,
I'm pulling my hair out with this and I thought I'd see if the greater Java experience of others might be able to shed some light on the problem. There is a large amount of program code I have written, which is itself within a larger project so I can't simply post it. However, I will outline the problem...
The issue: My code does not return predicatble results from a simulation. Each time the simulation is run, various statistics are recorded. Despite the fact that the code is identical (!), the results produced differ between executions.
Things I am pretty sure are not a problem (although if you think there's a "gotcha" please shout out):
- A random number generator is used but it is seeded with the same value each time.
- The program is single threaded so race conditions should not be an issue.
- Behaviour occurs in both debug mode, standalone jar and normal execution from the IDE (I'm using eclipse).
- Static members are used between objects in lists. The for-each construct is used, but this should execute in the same order each time.
- In the case of sorting the lists just mentioned, Collections.sort() is utilised and so should be stable (again, lists should be ordered in the same order)
Can anyone think of something I might be overlooking here? This seems unfathomable at the moment! Thanks!