For some reason I'm getting an error with the Random object I created and I can't see any reason why. Can someone please help? I'd be very appreciative!
public static void experiment(String method, String testType, int arraySize, int trials){
int[] intArray = new int[arraySize];
Random rand = new Random();
Long startTime;
Long endTime;
Long duration;
String durationStr;
String arraySizeStr = String.valueOf(arraySize);
for (int i =0; i<arraySize;i++){
intArray[i] = i;
}
if (method=="exhaustive"){
if (testType =="worst"){
for (int j = 0; j<= trials; j++){
startTime = System.currentTimeMillis();
exhaustive(intArray, intArray[arraySize-1]*3);
endTime = System.currentTimeMillis();
duration = endTime - startTime;
durationStr = duration.toString();
System.out.println("Exhaustive, Worst, " + durationStr + ", Array Size: " + arraySizeStr);
}
}
else{
for (int j = 0; j<= trials; j++){
startTime = System.currentTimeMillis();
exhaustive(intArray, rand.nextInt((arraySize -1) * 2));
endTime = System.currentTimeMillis();
duration = endTime - startTime;
durationStr = duration.toString();
System.out.println("Exhaustive, Best, " + durationStr + ", Array Size: " + arraySizeStr);
}
}
}