Search code examples
simulationanylogicagent-based-modeling

Generate a random date within a given range in anylogic


I have an agent Container, which has a parameter departure_date. I want to generate random future dates for this parameter. The date should be between current date and next 30 days. How can I achieve this?

Thank you in advance.


Solution

  • It is not clear whether your parameter is of type Date or double. I'll provide you with a solution for each case.

    • Date

    departure_date = addToDate(date(), DAY, random()*30);

    • Double - assuming your model time unit is DAYS

    departure_date = time() + random()*30