toxgene.core.random.ToxUniform Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ToxGene Show documentation
Show all versions of ToxGene Show documentation
Modified ToXGene for the iBench project.
The newest version!
/**
* Implements a random generator for uniform probability distributions
*
* @author Denilson Barbosa
* @version 0.1
*/
package toxgene.core.random;
import java.util.Random;
import toxgene.core.genes.CreateGeneException;
public class ToxUniform implements ToxRandom{
private float min, max;
private Random rand;
public ToxUniform(float min, float max, long seed){
this.min = min;
this.max = max;
if (max < min){
throw new CreateGeneException("invalid (min,max) values for uniform "
+"distribution: ("+min+","+max+")");
}
rand = new Random(seed);
}
public long nextInt(){
return (Math.round((double)nextFloat()));
}
public float nextFloat(){
return (min + ((max-min) * rand.nextFloat()));
}
public float minValue(){
return min;
}
public float maxValue(){
return max;
}
public long nextInt(float value) throws RuntimeException{
if (value < min){
throw new RuntimeException();
}
return (Math.round((double)min + ((value-min) * rand.nextFloat())));
}
}