#Java 8, 127 122 121 bytes
Java 8, 127 122 121 bytes
import java.util.*;a->{List l=new Stack();for(int i:a)for(int j=i;j-->0;Collections.shuffle(l))l.add(i);return l.get(0);}
-1 byte thanks to @Nevay.
Uses a similar approach as @ErikTheOutgolfer's Jelly answer, by adding n
times the item n
to the list, and then select one randomly from that list.
Explanation:
import java.util.*; // Required import for List, Stack and Collections
a->{ // Method with integer-array parameter and integer return-type
List l=new Stack(); // Create a List
for(int i:a) // Loop (1) over the input array
for(int j=i;j-->0; // Inner loop (2) from `i` down to 0
Collections.shuffle(l))
// and shuffle the List randomly after every iteration
l.add(i); // Add `i` that many times to List `l`
// End of inner loop (2) (implicit / single-line body)
// End of loop (1) (implicit / single-line body)
return l.get(0); // And then return the first item of the list
} // End of method