I would like to simulate the probability of producing good products and also defects with let's say 80% probability.
I've seen that it's possible to generate numbers and see if they are equal to the probability I'm looking for. But I'm not that good at Java programming and AnyLogic is a bit different than Java in that I can't call libraries etc I think.
I have tried this but it doesn't work. Only parts_count
keeps getting incremented but not parts_defect
which stays at 0 during the whole simulation. What am I doing wrong? Thanks
double probability = normal();
if ( -2<probability || probability<2){
parts_count += 1;
} else if ( -2>probability || probability>2){
parts_defect +=1;
}
PS. normal() generates a normal distribution with sigma = 1 and mean = 0. I know 2*sigma is not equal to 80% I was just trying out for the sake of the example.
That's because if ( -2<probability || probability<2){ is actually the same as saying that probability can take any value
you are saying probability bigger than -2 or probability smaller than 2... This is true for all the numbers of the world
Instead you should do
if( abs(probability)<2)
parts_count+=1;
else
parts_defects+=1;