DynamiX
DynamiX

Reputation: 63

AnyLogic: Same random value for every simulation run?

I want to simulate a discrete-event simulation which contains 6 processes as delays. At model startup I want to initialize the delay times for every delay/process station. I have written a java class "Prozess2" and every "Prozess2" object contains 6 CustomDistributions. At object initialization of "Prozess2" I draw one random value for any of them. In the end, I aggregate the 6 random values to the delay time. enter image description here Therefore, I always want to get other random values at startup for any delay time. However, when I run the simulation over and over again, I always get the same aggregated delay time by Math.round(time()).

In the constructor of "Prozess2" I hand over a RandomNumberGenerator called rng, which lies on the main agent and an instance of the main agent:enter image description here enter image description here Where is my mistake?

Upvotes: 0

Views: 546

Answers (2)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3965

In my opinion, it is best practice to explicitly supply your model with a random seed as one of the parameters and then use this seed to generate a random variable for each and every process that has randomness. That way you can be assured that if you change one part of the model, either through logic it input, that the other parts will still have the same random stream as they had before.

See example below:

enter image description here

And then you can use it enter image description here

So in your case pass the seed to the model and use it instead of the getDefaualtRandomGenerator()

You can also see this question for a similar problem to do with randomness Why do two flowcharts set up exactly the same end with different results every time the simulation is run even when I use a fixed seed?

Upvotes: 1

Yashar Ahmadov
Yashar Ahmadov

Reputation: 1636

AnyLogic will generate same random number if you manually run the exactly same model multiple times. The numbers will change in case if you add new blocks, or delete some of the existing ones in your model. To my understanding, they use the data in your model (blocks, variables, parameters, etc.) to add noise into the random number generator. That being said, the correct way of having different outputs for different runs is to use the Parameters Variation experiment as below:

Right click on your model name in the AnyLogic window, select New, then Experiment. You will see this screen. Select Parameters Variation:

enter image description here

On the Properties window, you have three options for Randomness. By selecting the first option, you will have different random numbers for different runs.

enter image description here

Upvotes: 0

Related Questions