0
votes

I need a function which calculate the capacity. I want that the function calculate for each Agent(agentOfPopulation) a random numeral between 70 and 90. My code:

int agentOfPopulation; 
for (int i = 0; i < main.agentOfPopulation.size(); i++){
agentOfPopulation = (int) (Math.random()*90+70);
}

The code doesn't works. Has somebody an idea to solve the problem?

2

2 Answers

0
votes

The way your random function is written it will generate numbers between 70 and 159. If you want random numbers between 70 and 90 inclusive, you want:

agentOfPopulation = (int) (Math.random()*21+70);
0
votes

Use the uniform function

agentOfPopulation=uniform(70,90);

If you want a discrete number:

agentOfPopulation=uniform_discr(70,90);