So I was looking to randomize the way certain methods are called, so that each one is only called once per instance and every single method is called.
So say one instance they are called in the order:
method2 method4 method3 method1
but in the next instance they are called in a different order:
method3 method2 method1 method4
The code that I have to randomize the order looks like this:
public void randomCalls(){
int[] order = new int[4];
for(int i=0; i<order.length; i++){
order[i]=nextNumber(order);
}
}
public int nextNumber(int[] array){
Random r = new Random();
int x = r.nextInt();
for(int i=0; i<array.length; i++){
if(arrayHasNumber(array,x)){
x = nextNumber(array);
}
}
return x;
}
public boolean arrayHasNumber(int[] array, int x){
for(int i=0;i<array.length;i++){
if(array[i]==x){
return true;
}
}
return false;
}