How to generate random true/false result in Anylogic

Viewed 133

Iam new to anylogic. I want to generate random true false results to control parameter in Select Output.

I used this if else conditions in my source


if(randomTrue(0.25)){
    if(randomTrue(0.5)){
        agent.isOnlineRezerve = true;
    }else { 
        agent.isOnlineRezerve = false;
    }
}else{
    agent.isOnlineRezerve = false;
}

My condition of source output is

agent.isOnlineRezerve

Every time I run it it gives me 128 out of 1000 true and the rest false

I want to get a number other than 128 each time, but I couldn't do it. I would be glad if you help.

2 Answers

AnyLogic is using a fixed seed to the random number generator, so that independent runs produce equivalent results. To switch to a random seed:

To set up random number generator seed

  1. In the Projects view, select the experiment you are currently working with.

  2. Go to the Randomness section of the Properties view.

  3. In the Random number generation group of buttons:

  • To set random seed, choose the Random seed (unique experiments) option.

  • To set fixed seed, choose the Fixed seed (reproducible experiments) option > and enter the seed value in the Seed value edit box.

From https://anylogic.help/anylogic/stochastic/random-number-generator.html

Another answer to this question, is to use the second argument of that function in order to use your own random number generator with a seed of your choice:

randomTrue(0.5,new Random())

And if you want to use your own seed for an individual calculation

randomTrue(0.5,new Random(33))
Related