private static double[] poissonRandCalc(Random rr, double mean, int n) {
		double[] ran = new double[n];
		double oldm = -1.0D;
		double expt = 0.0D;
		double em = 0.0D;
		double term = 0.0D;
		double sq = 0.0D;
		double lnMean = 0.0D;
		double yDev = 0.0D;

		if (mean < 12.0D) {
			for (int i = 0; i < n; i++) {
				if (mean != oldm) {
					oldm = mean;
					expt = Math.exp(-mean);
				}
				em = -1.0D;
				term = 1.0D;
				do {
					++em;
					term *= rr.nextDouble();
				} while (term > expt);
				ran[i] = em;
			}
		} else {
			for (int i = 0; i < n; i++) {
				if (mean != oldm) {
					oldm = mean;
					sq = Math.sqrt(2.0D * mean);
					lnMean = Math.log(mean);
					expt = lnMean - Stat.logGamma(mean + 1.0D);
				}
				do {
					do {
						yDev = Math.tan(Math.PI * rr.nextDouble());
						em = sq * yDev + mean;
					} while (em < 0.0D);
					em = Math.floor(em);
					term = 0.9D * (1.0D + yDev * yDev) * Math.exp(em * lnMean - Stat.logGamma(em + 1.0D) - expt);
				} while (rr.nextDouble() > term);
				ran[i] = em;
			}
		}
		return ran;
	}