I require help with a small Java problem I am having. I have an array called lowest. An example entry of lowest would be [6 2 9 2 7 2 3].
What I need to do is choose the lowest number from the array, and if there are two or more entries which are the lowest and identical, I need to choose one randomly. So in this case, since 2 is the lowest, I would have to choose either entry 1, 3 or 5 randomly.
How do I do this?
Find the indexes in a loop and put them in a collection (e.g. ArrayList lowest). Then use Collections.shuffle(lowest) and pick the first element lowest.get(0). This should do what you want.