package jp.rel.jmtrandom;

public class Random {
	
	private final MTRandInterface mtrand;
	
	private int normal_sw;
	private double normal_save;

	public Random(long seed) {
		this.mtrand = new MT64(seed);
	}

	public Random(MTRandInterface mtrand) {
		this.mtrand = mtrand;
	}

	public double nextUnif() {
		return mtrand.genRandRealo0o1();
	}

	public double nextNormal() {
		if (normal_sw == 0) {
			double t = Math.sqrt(-2 * Math.log(this.nextUnif()));
			double u = Math.PI * this.nextUnif();
			normal_save = t * Math.sin(u);
			normal_sw = 1;
			return t * Math.cos(u);
		} else {
			normal_sw = 0;
			return normal_save;
		}
	}

	public double nextNormal(double mu, double sig) {
		return mu + sig * this.nextNormal();
	}

	public double nextExp(double r) {
		return -Math.log(this.nextUnif()) / r;
	}

}

@@ -331,32 +331,258 @@
 Realo0o1();%0A%09%7D%0A%0A
+%09public double nextUnif(double low, double high) %7B%0A%09%09return (high - low) *  mtrand.genRandRealo0o1() + low;%0A%09%7D%0A%0A%09public double nextExp(double beta) %7B%0A%09%09return -Math.log(this.nextUnif()) / beta;%0A%09%7D%0A%0A%09/* Normal distribution */%0A%0A
 %09public double n
@@ -595,16 +595,16 @@
 mal() %7B%0A
-
 %09%09if (no
@@ -973,33 +973,888 @@
 next
-Exp(double r) %7B%0A%09%09return 
+TruncNormal(double mu, double sig) %7B%0A%09%09double tmp;%0A%09%09do %7B%0A%09%09%09tmp = this.nextNormal(mu, sig);%0A%09%09%7D while (tmp %3E 0.0);%0A%09%09return tmp;%0A%09%7D%0A%0A%09public double nextLogNormal(double mu, double sig) %7B%0A%09%09return Math.exp(nextNormal(mu, sig));%0A%09%7D%0A%0A%09/* Logistic distribution */%0A%0A%09public double nextLogistic() %7B%0A    %09double x = this.nextUnif();%0A    %09return Math.log(x/(1.0-x));%0A    %7D%0A%0A    public double nextLogistic(double mu, double phi) %7B%0A%09%09return mu + phi * this.nextLogistic();%0A    %7D%0A%0A    public double nextTruncLogistic(double mu, double phi) %7B%0A%09%09double tmp;%0A%09%09do %7B%0A%09%09%09tmp = this.nextLogistic(mu, phi);%0A%09%09%7D while (tmp %3E 0.0);%0A%09%09return tmp;%0A    %7D%0A%0A%09public double nextLogLogistic(double mu, double phi) %7B%0A%09%09return Math.exp(nextLogistic(mu, phi));%0A%09%7D%0A%09%0A%09/* Extreme distribution */%0A%0A%09// TODO%0A%09%0A%09/* Weibull distribution */%0A%0A%09public double nextWeibull(double alpha, double beta) %7B%0A%09%09return Math.pow(
 -Mat
@@ -1878,17 +1878,32 @@
 if()) / 
-r
+beta, 1.0/alpha)
 ;%0A%09%7D%0A%0A%7D%0A

add several distributions