jeudi 9 avril 2015

Java Random.nextDouble() not uniform?

I'm writing an ER simulator which uses 5 priority levels (1-5). I have percentages from a histogram and am slotting new arrivals into bins based on a randomly generated double with range from 0-1. I've run it with multiple seeds, for approximately 1000 patients each and I've noticed that there is always a disproportionately small number of priority level 5's. Have I made a mistake? I've checked the math, printed out the values and they all equal what they should.


The division by 98.3 is to correct for the unknown values in the histogram.



public static int priority(Random stream){
double resus=(0.6/98.3);
double emerg=(13.5/98.3)+resus;
double urge=(38.6/98.3)+emerg;
double lurge=(37.1/98.3)+urge;
double non=(8.5/98.3)+lurge;
double source=stream.nextDouble();
if(source<resus){
return 1;
}
if(source<emerg){
return 2;
}
if(source<urge){
return 3;
}
if(source<lurge){
return 4;
}
if(source<non){
return 5;
}
return 0;
}




Aucun commentaire:

Enregistrer un commentaire