@@ -0,0 +1,1564 @@
+package com.k13n.soliton;%0A%0Aimport java.util.Random;%0A%0Apublic class RobustSolitonGenerator implements SolitonGenerator %7B%0A  private Random random;%0A  private int k;%0A  private double c, delta, R, beta;%0A%0A  public RobustSolitonGenerator(int k, double c, double delta, long seed) %7B%0A    this.k = k;%0A    this.c = c;%0A    this.delta = delta;%0A    random = new Random(seed);%0A    R = computeR();%0A    beta = computeBeta();%0A  %7D%0A%0A  public RobustSolitonGenerator(int k, double c, double delta) %7B%0A    this(k, c, delta, new Random().nextLong());%0A  %7D%0A%0A  private double computeR() %7B%0A    return c * Math.log(k / delta) * Math.sqrt(k);%0A  %7D%0A%0A  private double computeBeta() %7B%0A    double sum = 0;%0A    for (int i = 1; i %3C= k; i++)%0A      sum += idealSoliton(i) + unnormalizedRobustSoliton(i);%0A    return sum;%0A  %7D%0A%0A  @Override%0A  public int next() %7B%0A    double u = random.nextDouble();%0A    return inverseTransformSampling(u);%0A  %7D%0A%0A  private int inverseTransformSampling(double u) %7B%0A     double sum = 0;%0A     int index = 1;%0A     while (sum %3C= u)%0A       sum += normalizedRobustSoliton(index++);%0A     return index - 1;%0A  %7D%0A%0A  private double normalizedRobustSoliton(int i) %7B%0A    return (idealSoliton(i) + unnormalizedRobustSoliton(i)) / beta;%0A  %7D%0A%0A  private double unnormalizedRobustSoliton(int i) %7B%0A    if (1 %3C= i && i %3C= Math.floor(k/R)-1)%0A      return R / (i*k);%0A    else if (i == Math.floor(k / R))%0A      return R * Math.log(R / delta) / k;%0A    else%0A      return 0;%0A  %7D%0A%0A  private double idealSoliton(int i) %7B%0A    if (i == 1)%0A      return 1.0 / k;%0A    else%0A      return 1.0 / (i * (i-1));%0A  %7D%0A%0A%7D%0A

Implement a robust soliton random number generator