2

I have several delays that are all distributed. These distributions involve random number generation.

I want each processing station to have its own RNG. According to anylogic I can simply create an instance (for example: Random myRNG1 = newRandom(); ) and then use this in the distribution: triangular(5, 10, 25, myRNG1).

Unfortunately, I don't know where exactly I insert the code Random myRNG1 = newRandom();. If I do it in the field "onStartup" in the main agent and then use the generator with triangular(5, 10, 25, myRNG) in the delayblock, I get the following error message: myRNG1 cannot be resolved to a variable.

It seems that the own random generator is not publicly visible. How can I change this?

Thanks in advance!

1 Answers1

2

Drag in a variable, change the type to Random and initialize it as below: enter image description here

Now, you can refer to it as the RNG to be used, i.e. when calling uniform(0,10, v_MyRNG))

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • Thank you very much! That helped me a lot and it works. What unfortunately doesn't work is when I want to pass in new Random(v_seed) a custom seed with variable. Strangely enough it works if I write a correct number in as seed new Random(12345). Can you tell me how to do this with a variable or does it not work at all? Thanks a lot in advance. – Norbert Rötgen Jul 14 '23 at 13:19