Modeling tips for reproducibility: how to fix unreproducible models

Robotic arms

At the AnyLogic Support Team, we often hear from users struggling with unreproducible simulation results. If you’ve ever run a model with a fixed random seed but still got different results each time, this guide is for you. Below, we’ve compiled a list of common issues that can cause randomness in your model and practical tips to ensure reproducible results.

Common sources of randomness in models

Here are the most frequent culprits that can make your simulation results unpredictable:

  1. Avoid HashMap or HashSet collections

    Use LinkedHashMap instead. Hash-based collections can introduce randomness due to their internal structure.

  2. Don’t use object.hashCode() or System.identityHashCode()

    These functions can produce inconsistent results across runs.

  3. Avoid time-based functions

    Functions like System.currentTimeMillis() or new Date() rely on system time, which changes with every run. Remove them from your model logic.

  4. Restart the model completely

    Reproducible results require a full restart (close and reopen the model window). If you run multiple experiments in a row (Start -> Stop -> Start), leftover data from previous runs (e.g., static variables) can affect the results.

  5. Check external data sources

    Ensure your input data isn’t changing during the simulation. Modified input data can lead to different results in each run.

  6. Use the default random number generator

    Avoid custom random classes like Collections.shuffle() or Math.random(). Instead, use getDefaultRandomNumberGenerator() to access the model’s random number stream.

  7. Fix model start/stop dates

    If your model converts dates to simulation time, ensure the start and stop dates are consistent.

  8. Synchronize custom parallel threads

    If you’re using custom parallel threads, make sure they’re properly synchronized and ordered.

  9. Avoid dynamic properties in shapes

    Dynamic properties in shapes should not contain functions that alter the model’s state.

Tips for experiments with multiple iterations

When running experiments with multiple iterations, a few extra steps can ensure your results stay consistent. First, be cautious with static variables—they’re shared across all iterations, so changes in one run can affect the next. Make sure to reset them or avoid using them altogether.

Next, always reset the random number generator before starting a new iteration. If you don’t, the random stream continues from where it left off, leading to unpredictable results. For optimization experiments, parallel evaluations can speed things up but may cause variability due to differences in execution speed. If reproducibility is critical, disable parallel evaluations to keep results consistent.

Finally, if your results don’t match those from a standard simulation experiment, double-check settings like start/stop times, random seeds, and how simultaneous events are handled. Small differences here can lead to big discrepancies. By paying attention to these details, you can ensure your multi-iteration experiments are reliable and reproducible.

Final thoughts

Reproducible results are crucial for reliable simulations. By following these modeling tips for reproducibility, you can avoid common pitfalls and ensure your model behaves consistently. If you’re still facing issues, double-check your model against this list or reach out to the AnyLogic Support Team for help.


For more tips and updates, subscribe to our newsletter and stay tuned!

Related posts