Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* This file is part of jasima, v1.3, the Java simulator for manufacturing and
* logistics.
*
* Copyright (c) 2015 jasima solutions UG
* Copyright (c) 2010-2015 Torsten Hildebrandt and jasima contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*******************************************************************************/
package jasima.core.random.continuous;
import jasima.core.util.Pair;
import java.util.Random;
/**
* Returns a uniformly distributed real number in the range [min, max).
*
* @author Torsten Hildebrandt
* @version
* "$Id: DblUniformRange.java 753 2015-07-27 15:29:49Z [email protected] $"
*/
public class DblUniformRange extends DblStream {
private static final long serialVersionUID = 7183118564770349548L;
private double min = 0.0d, max = 1.0d, range = 1.0d;
public DblUniformRange(double min, double max) {
this(null, null, min, max);
}
public DblUniformRange(Random random, double min, double max) {
this(random, null, min, max);
}
public DblUniformRange(String name, double min, double max) {
this(null, name, min, max);
}
public DblUniformRange(Random random, String name, double min, double max) {
super();
setRange(min, max);
setRndGen(random);
setName(name);
}
public void setRange(double min, double max) {
checkValues(min, max);
this.min = min;
this.max = max;
}
@Override
public void init() {
checkValues(min, max);
super.init();
range = max - min;
}
@Override
public double nextDbl() {
return min + range * rndGen.nextDouble();
}
@Override
public double getNumericalMean() {
return (getMin() + getMax()) / 2.0;
}
@Override
public String toString() {
return "DblUniformRange(min=" + min + ";max=" + max + ")";
}
@Override
public Pair getValueRange() {
return new Pair<>(getMin(), getMax());
}
private void checkValues(double min, double max) {
if (min > max)
throw new IllegalArgumentException("min>max " + min + " " + max);
}
public double getMin() {
return min;
}
/**
* Sets the minimum value returned by this number stream.
*
* @param min
* The minimum to use.
*/
public void setMin(double min) {
this.min = min;
}
public double getMax() {
return max;
}
/**
* Sets the maximum value returned by this number stream.
*
* @param max
* The maximum to use.
*/
public void setMax(double max) {
this.max = max;
}
}