All Downloads are FREE. Search and download functionalities are using the official Maven repository.

toxgene.core.random.ToxUniform Maven / Gradle / Ivy

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())));
  }  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy