I think I see your point.  I've followed through the logic in the case when build_random_function(2,1) and I can see it will be infinite recursion. 

I think I can fix it by changing the conditionals to <= 1 for both min_depth, max_depth.