/** * Creates a new continuous random number generator. * * @param numGen the actual random number generator that will be the base * to generate random numbers following a continuous distribution. * @param seed the seed to initialize the random number generator. If * it is passed -1, the current time will be used */ protected ContinuousDistributionAbstract(RealDistribution numGen, long seed) { this.numGen = numGen; if(seed == -1) seed = System.currentTimeMillis(); setSeed(seed); }
@Override public double sample() { final double variate = super.sample(); double num = 1; double nextNum = 1 + 1 / Math.pow(2, shape); double j = 3; while (variate > nextNum / den) { num = nextNum; nextNum += 1 / Math.pow(j, shape); j++; } return num / den; }