For example if I have an array of ints like this:
int[] list = {1, 4, 2};
And I want to choose one of these 3 numbers, but have the greater values get chosen more frequently:
1 get chosen 1/7 of the time
4 gets chosen 4/7 of the time
2 gets chosen 2/7 of the time
How can I write a function for this, if there isn't already one in Java.
Edit: I'm looking for an efficient solution, O(n) or better.
I'm going to be running this code a lot times in many threads. Building a new list is not sufficient.