int lowestIndex = 0;
//Make sure we start with the biggest number possible
int lowestValue = Integer.MAX_VALUE;
for(int i = 0; i < array.length; i++){
if(array[i] < lowestValue){
lowestValue = array[i];
lowestIndex = i;
}
}
Now lowestIndex is the index of the lowest number!
Now this will always return the first of the lowest values. If you want to get a random lowest, you'll have make an array or ArrayList with the indexes of all the elements being the same as the lowest and then choose randomly. It depends on how big this array is and how efficient you want it to be. If efficiency is no big problem, you can do this after the code above:
Random rand = new Random();
ArrayList<Integer> minIndexes = new ArrayList<Integer>();
for(int i = 0; i < array.length; i++){
if(array[i] == lowestValue){
minIndexes.add(i);
}
}
int r = rand.next(minIndexes.size());
int randomIndex = minIndexes.get(r);
Now randomIndex is the index you want!
What I need to do is choose the lowest number from the array- no, you need to choose an index, of the lowest number.