package psoAlgoCode; import java.util.Random; import java.util.Vector; public class RandomFunctions { static Random random = new Random(); public static Vector nextDoubles(int dimension) { Vector result = new Vector(); for (int i = 0; i < dimension; i++) { result.addElement(Function.lowerLimit + random.nextDouble() * (Function.upperLimit * 2)); } return result; } public static Vector nextRandoms(int dimension) { Vector result = new Vector(); for (int i = 0; i < dimension; i++) { result.addElement(random.nextDouble()); } return result; } public static Vector nextBoolean(int dimension) { Vector result = new Vector(); for (int i = 0; i < dimension; i++) { result.addElement(random.nextBoolean()); } return result; } // The paper Modified binary particle swarm optimization from S. Lee states that // phi is a random number between 2.4 and 2.01 public static double randomPhi() { double result = 0.0; result = (random.nextDouble() * (2.4 - 2.01)) + 2.01; return result; } }