Revert back to java.util.Random
This commit is contained in:
parent
3e3df4d8a2
commit
09dabcdd41
@ -5,7 +5,7 @@ import eva2.tools.math.RNG;
|
|||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.security.SecureRandom;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fletcher-Powell function with up to 2^n optima from Shir&Baeck, PPSN 2006,
|
* Fletcher-Powell function with up to 2^n optima from Shir&Baeck, PPSN 2006,
|
||||||
@ -40,7 +40,7 @@ public class F19Problem extends AbstractProblemDouble implements
|
|||||||
public void initializeProblem() {
|
public void initializeProblem() {
|
||||||
super.initializeProblem();
|
super.initializeProblem();
|
||||||
// create static random data
|
// create static random data
|
||||||
SecureRandom rand = new SecureRandom();
|
Random rand = new Random();
|
||||||
rand.setSeed(randSeed);
|
rand.setSeed(randSeed);
|
||||||
alphas = RNG.randomDoubleArray(rand, -Math.PI, Math.PI, dim);
|
alphas = RNG.randomDoubleArray(rand, -Math.PI, Math.PI, dim);
|
||||||
A = RNG.randomIntArray(rand, -100, 100, dim * dim);
|
A = RNG.randomIntArray(rand, -100, 100, dim * dim);
|
||||||
|
@ -4,7 +4,7 @@ import eva2.tools.EVAERROR;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.security.SecureRandom;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random number generator used across all optimizations
|
* Random number generator used across all optimizations
|
||||||
@ -12,7 +12,7 @@ import java.security.SecureRandom;
|
|||||||
*/
|
*/
|
||||||
public class RNG {
|
public class RNG {
|
||||||
|
|
||||||
private static SecureRandom random;
|
private static Random random;
|
||||||
private static long randomSeed;
|
private static long randomSeed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +20,7 @@ public class RNG {
|
|||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
randomSeed = System.currentTimeMillis();
|
randomSeed = System.currentTimeMillis();
|
||||||
random = new SecureRandom();
|
random = new Random();
|
||||||
random.setSeed(randomSeed);
|
random.setSeed(randomSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class RNG {
|
|||||||
if (randomSeed == 0) {
|
if (randomSeed == 0) {
|
||||||
setRandomSeed();
|
setRandomSeed();
|
||||||
} else {
|
} else {
|
||||||
random = new SecureRandom();
|
random = new Random();
|
||||||
random.setSeed(randomSeed);
|
random.setSeed(randomSeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,14 +51,14 @@ public class RNG {
|
|||||||
*/
|
*/
|
||||||
public static void setRandomSeed() {
|
public static void setRandomSeed() {
|
||||||
randomSeed = System.currentTimeMillis();
|
randomSeed = System.currentTimeMillis();
|
||||||
random = new SecureRandom();
|
random = new Random();
|
||||||
random.setSeed(randomSeed);
|
random.setSeed(randomSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static void setRandom(SecureRandom baseRandom) {
|
public static void setRandom(Random baseRandom) {
|
||||||
random = baseRandom;
|
random = baseRandom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ public class RNG {
|
|||||||
* @param hi Upper bound.
|
* @param hi Upper bound.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static int randomInt(SecureRandom rand, int lo, int hi) {
|
public static int randomInt(Random rand, int lo, int hi) {
|
||||||
if (hi < lo) {
|
if (hi < lo) {
|
||||||
System.err.println("Invalid boundary values! Returning zero.");
|
System.err.println("Invalid boundary values! Returning zero.");
|
||||||
return -1;
|
return -1;
|
||||||
@ -196,7 +196,7 @@ public class RNG {
|
|||||||
return (hi - lo) * random.nextDouble() + lo;
|
return (hi - lo) * random.nextDouble() + lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double randomDouble(SecureRandom rand, double lo, double hi) {
|
public static double randomDouble(Random rand, double lo, double hi) {
|
||||||
return (hi - lo) * rand.nextDouble() + lo;
|
return (hi - lo) * rand.nextDouble() + lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ public class RNG {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double[] randomDoubleArray(SecureRandom rand, double lower, double upper, int size) {
|
public static double[] randomDoubleArray(Random rand, double lower, double upper, int size) {
|
||||||
double[] result = new double[size];
|
double[] result = new double[size];
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
result[i] = RNG.randomDouble(rand, lower, upper);
|
result[i] = RNG.randomDouble(rand, lower, upper);
|
||||||
@ -262,9 +262,9 @@ public class RNG {
|
|||||||
* Create a uniform random integer vector within the given bounds
|
* Create a uniform random integer vector within the given bounds
|
||||||
* (inclusive) in every dimension.
|
* (inclusive) in every dimension.
|
||||||
*
|
*
|
||||||
* @param n
|
|
||||||
* @param lower
|
* @param lower
|
||||||
* @param upper
|
* @param upper
|
||||||
|
* @param size
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int[] randomIntArray(int lower, int upper, int size) {
|
public static int[] randomIntArray(int lower, int upper, int size) {
|
||||||
@ -275,7 +275,7 @@ public class RNG {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] randomIntArray(SecureRandom rand, int lower, int upper, int size) {
|
public static int[] randomIntArray(Random rand, int lower, int upper, int size) {
|
||||||
int[] result = new int[size];
|
int[] result = new int[size];
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
result[i] = RNG.randomInt(rand, lower, upper);
|
result[i] = RNG.randomInt(rand, lower, upper);
|
||||||
@ -448,7 +448,6 @@ public class RNG {
|
|||||||
/**
|
/**
|
||||||
* Create a normalized random vector with gaussian random double entries.
|
* Create a normalized random vector with gaussian random double entries.
|
||||||
*
|
*
|
||||||
* @param n
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static double[] gaussianVector(double dev, double[] result,
|
public static double[] gaussianVector(double dev, double[] result,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user