19package denoptim.utils;
21import java.util.Collection;
23import javax.vecmath.Point3d;
25import org.apache.commons.math3.random.MersenneTwister;
27import denoptim.exception.DENOPTIMException;
28import denoptim.io.DenoptimIO;
45 private MersenneTwister
mt =
null;
50 private final boolean debug =
false;
137 private void print(Object val, String type)
139 String sss =
"asked for "+ type +
" "+val.toString();
142 Exception ex =
new Exception();
143 for (
int i=0; i<5;i++)
145 String cn = ex.getStackTrace()[i].getClassName();
146 if (!cn.contains(
"RandomUtils"))
148 sss = sss + ex.getStackTrace()[i].getClassName() +
":"
149 + ex.getStackTrace()[i].getLineNumber()+
" ";
172 double d =
getRNG().nextDouble();
189 double d =
getRNG().nextGaussian();
206 int r =
getRNG().nextInt(i);
221 boolean r =
getRNG().nextBoolean();
259 return new Point3d(maxAbsValue*xFactor*xSign,
260 maxAbsValue*yFactor*ySign,
261 maxAbsValue*zFactor*zSign);
280 return new Point3d(maxAbsValue*xFactor,
282 maxAbsValue*zFactor);
304 int chosen =
nextInt(c.size());
331 rndSeed = System.currentTimeMillis();
Utility methods for input/output.
static void writeData(String fileName, String data, boolean append)
Write text-like data file.
Tool to generate random numbers and random decisions.
MersenneTwister mt
The implementation of the pseudo-random number generation.
boolean nextBoolean(double prob)
Returns whether the next pseudo-random, uniformly distributed double is lower than the specified valu...
long rndSeed
Seed used to control the generation of random numbers and decisions.
boolean nextBoolean()
Returns the next pseudo-random, uniformly distributed boolean value from this random number generator...
public< T > T randomlyChooseOne(Collection< T > c)
Chooses one member among the given collection.
Randomizer(long seed)
Constructor that specifies the random seed.
MersenneTwister getRNG()
Returns the random number generator.
int nextInt(int i)
Returns a pseudo-random, uniformly distributed int value between 0 (inclusive) and the specified valu...
Point3d getNormallyNoisyPoint(double maxAbsValue)
Returns a point in three-dimensional space with a random set of coordinates, the absolute value of wh...
final boolean debug
local flag used only to enable highly detailed logging.
double nextNormalDouble()
Returns the next pseudo-random, normally distributed double value between 0.0 and 1....
void initialiseRNG()
Initializes this random number generator (RNG) using a random seed that is generated on-the-fly rando...
double nextDouble()
Returns the next pseudo-random, uniformly distributed double value between 0.0 and 1....
Point3d getNoisyPoint(double maxAbsValue)
Returns a point in three-dimensional space with a random set of coordinates, the absolute value of wh...
void print(Object val, String type)
Utility to debug: writes some log in file '/tmp/rng_debug_log'.
void setSeed(long value)
Sets the random seed.
void initialiseRNG(long seed)
Initialized this random number generator using the given seed.