For UT, you might find it easier to break this into one function that does selection based on a specified value, and a wrapper that picks a random number and then calls the first function.