Is there any ways I can write redundant-less code without this infinite loop? I have also tried putting the conditions and the generating number, but since it has two conditions, the output number will be different.
private static final int PERCENT_97 = 3;
/**
* Returns returns a pseudo-random Gaussium number. Forumla:
* {@code (RanGassium * 3) + mean }
*
* @param mean
* mean of returning value
* @param min
* min bound
* @param max
* max bound
* @return a pseduo-random Gaussium that is close to the mean.
*/
public static double getRandomGaussium(double mean, double min, double max) {
double returningNumber = 0;
double rangeMean=(max-min)/2;
while (true) {
returningNumber = (generator.nextGaussian() * rangeMean/PERCENT_97) + mean;
if (returningNumber > min && returningNumber < max) {
break;
}
}
return returningNumber;
}