Returning a pseudo-random Gaussian number 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 &gt; min &amp;&amp; returningNumber &lt; max) {
            break;
        }
    }
    return returningNumber;
}
A do while would be an equivalent construct. I don't really think either is more or less preferable, but is an alternative that avoids the appearance of an infinite loop:

do {
    returningNumber = (generator.nextGaussian() * rangeMean/PERCENT_97) + mean;
} while (returningNumber &lt; min || returningNumber &gt; max);
return returningNumber;


That still leaves open a possibility of an eternal loop, though. You should probably at least validate your params to guard against that (eg., a min of 1 and max of 1 would run forever). You may also want to put an iteration counter to give up and throw an exception after so many iterations. At that point, a for loop with an early return if one is found may be a better choice than stuffing it all into the where or if conditionals:

for (int i = 0; i &lt; MAX_TRIES; i++) {
    returningNumber = (generator.nextGaussian() * rangeMean/PERCENT_97) + mean;
    if (returningNumber &gt; min &amp;&amp; returningNumber &lt; max) {
        return returningNumber;
    }
}
throw new IGiveUpException();