It would be easier to store values in an collection, and draw them out randomly until the collection is empty. Or better yet, shuffle the collection and then walk over it sequentially.
The values in the collection could be integers, or they could be objects of different classes (with a common superclass or interface), which provide different implementations of a call()
method.
For example:
import java.util.*;
import java.util.concurrent.*;
List<Runnable> functions = new ArrayList<Runnable>();
functions.add(new Runnable() {
public void run() { /* do something */ }
});
functions.add(new Runnable() {
public void run() { /* do something else */ }
});
Collections.shuffle(functions);
for(Runnable function : functions)
function.run();
The other posts on this thread show other potential solutions, but all of them are more complex and error-prone than this one, and most of them would be very slow if the number of functions is large. (The one from @AndersLinden is an exception -- it would still be fast even if there are thousands of functions to call.)